自动发现监控项脚本(我只需要一个key)
[root@master-mysql ~]# cat juniper.py
#!/usr/bin/python3
# encoding=utf-8
import paramiko
import json
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('192.168.2.2',22,'username','password',allow_agent=False,look_for_keys=False)
stdin, stdout, stderr = client.exec_command('show interfaces')
result = stdout.read().decode()
client.close()
data = list()
for i in result.splitlines():
if 'Physical interface' in i and 'Physical link is Up' in i :
data.append({"{#INTERFACE}": i.split(',')[0].split(' ')[2]})
print(json.dumps({"data": data}))
[root@master-mysql ~]# /root/juniper.py
{"data": [{"{#INTERFACE}": "ge-0/0/0"}, {"{#INTERFACE}": "ge-0/0/1"}, {"{#INTERFACE}": "ge-0/0/2"}, {"{#INTERFACE}": "ge-0/0/3"}, {"{#INTERFACE}": "ge-0/0/4"}, {"{#INTERFACE}": "ge-0/0/6"}, {"{#INTERFACE}": "ge-0/0/7"}, {"{#INTERFACE}": "ge-0/0/8"}, {"{#INTERFACE}": "ge-0/0/9"}, {"{#INTERFACE}": "ge-0/0/10"}, {"{#INTERFACE}": "ge-0/0/12"}, {"{#INTERFACE}": "ge-0/0/13"}, {"{#INTERFACE}": "ge-0/0/14"}, {"{#INTERFACE}": "ge-0/0/16"}, {"{#INTERFACE}": "ge-0/0/17"}, {"{#INTERFACE}": "ge-0/0/18"}, {"{#INTERFACE}": "ge-0/0/19"}, {"{#INTERFACE}": "ge-0/0/20"}, {"{#INTERFACE}": "ge-0/0/21"}, {"{#INTERFACE}": "ge-0/0/22"}, {"{#INTERFACE}": "ge-0/0/23"}, {"{#INTERFACE}": "ge-0/0/24"}, {"{#INTERFACE}": "ge-0/0/25"}, {"{#INTERFACE}": "ge-0/0/26"}, {"{#INTERFACE}": "ge-0/0/27"}, {"{#INTERFACE}": "ge-0/0/28"}, {"{#INTERFACE}": "ge-0/0/29"}, {"{#INTERFACE}": "ge-0/0/30"}, {"{#INTERFACE}": "ge-0/0/31"}, {"{#INTERFACE}": "ge-0/0/32"}, {"{#INTERFACE}": "ge-0/0/33"}, {"{#INTERFACE}": "ge-0/0/34"}, {"{#INTERFACE}": "ge-0/0/35"}, {"{#INTERFACE}": "ge-0/0/36"}, {"{#INTERFACE}": "ge-0/0/37"}, {"{#INTERFACE}": "ge-0/0/38"}, {"{#INTERFACE}": "ge-0/0/39"}, {"{#INTERFACE}": "ge-0/0/40"}, {"{#INTERFACE}": "ge-0/0/41"}, {"{#INTERFACE}": "ge-0/0/43"}, {"{#INTERFACE}": "ge-0/0/45"}, {"{#INTERFACE}": "ge-0/0/46"}, {"{#INTERFACE}": "ge-0/0/47"}, {"{#INTERFACE}": "xe-2/0/1"}, {"{#INTERFACE}": "ge-2/0/2"}, {"{#INTERFACE}": "xe-2/0/3"}, {"{#INTERFACE}": "xe-2/0/6"}, {"{#INTERFACE}": "ge-2/0/10"}, {"{#INTERFACE}": "ge-2/0/12"}, {"{#INTERFACE}": "ge-2/0/15"}, {"{#INTERFACE}": "xe-2/0/16"}, {"{#INTERFACE}": "xe-2/0/17"}, {"{#INTERFACE}": "xe-2/0/18"}, {"{#INTERFACE}": "xe-2/0/19"}, {"{#INTERFACE}": "xe-2/0/20"}, {"{#INTERFACE}": "xe-2/0/21"}, {"{#INTERFACE}": "ge-7/0/0"}, {"{#INTERFACE}": "ge-7/0/2"}, {"{#INTERFACE}": "ge-7/0/3"}, {"{#INTERFACE}": "ge-7/0/4"}, {"{#INTERFACE}": "ge-7/0/6"}, {"{#INTERFACE}": "ge-7/0/7"}, {"{#INTERFACE}": "ge-7/0/8"}, {"{#INTERFACE}": "ge-7/0/10"}, {"{#INTERFACE}": "ge-7/0/11"}, {"{#INTERFACE}": "ge-7/0/12"}, {"{#INTERFACE}": "ge-7/0/13"}, {"{#INTERFACE}": "ge-7/0/14"}, {"{#INTERFACE}": "ge-7/0/15"}, {"{#INTERFACE}": "ge-7/0/16"}, {"{#INTERFACE}": "ge-7/0/17"}, {"{#INTERFACE}": "ge-7/0/20"}, {"{#INTERFACE}": "ge-7/0/21"}, {"{#INTERFACE}": "ge-7/0/22"}, {"{#INTERFACE}": "ge-7/0/23"}, {"{#INTERFACE}": "ge-7/0/24"}, {"{#INTERFACE}": "ge-7/0/26"}, {"{#INTERFACE}": "ge-7/0/27"}, {"{#INTERFACE}": "ge-7/0/28"}, {"{#INTERFACE}": "ge-7/0/29"}, {"{#INTERFACE}": "ge-7/0/31"}, {"{#INTERFACE}": "ge-7/0/32"}, {"{#INTERFACE}": "ge-7/0/34"}, {"{#INTERFACE}": "ge-7/0/36"}, {"{#INTERFACE}": "ge-7/0/40"}, {"{#INTERFACE}": "ge-7/0/41"}, {"{#INTERFACE}": "ge-7/0/42"}, {"{#INTERFACE}": "ge-7/0/45"}, {"{#INTERFACE}": "ge-7/0/46"}, {"{#INTERFACE}": "ge-7/0/47"}, {"{#INTERFACE}": "ae0"}, {"{#INTERFACE}": "bme0"}, {"{#INTERFACE}": "bme1"}, {"{#INTERFACE}": "bme2"}, {"{#INTERFACE}": "bme3"}, {"{#INTERFACE}": "dsc"}, {"{#INTERFACE}": "gre"}, {"{#INTERFACE}": "ipip"}, {"{#INTERFACE}": "lo0"}, {"{#INTERFACE}": "lsi"}, {"{#INTERFACE}": "mtun"}, {"{#INTERFACE}": "pimd"}, {"{#INTERFACE}": "pime"}, {"{#INTERFACE}": "tap"}, {"{#INTERFACE}": "vlan"}]}```
> 根据监控项key采集数值脚本(2个脚本一个采集input pps ,一个output pps)
```shell
[root@master-mysql ~]# cat juniper_output_rate.py
#!/usr/bin/python3
# encoding=utf-8
import paramiko
import sys
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
argv1=sys.argv[1]
# connect to client
client.connect('192.168.2.2',22,'username','password',allow_agent=False,look_for_keys=False)
#stdin, stdout, stderr = client.exec_command('show interface ge-0/0/1')
stdin, stdout, stderr = client.exec_command('show interface '+argv1)
result = stdout.read().decode()
client.close()
try:
for i in result.splitlines():
if 'Output rate' in i :
r=i.split('(')[1].split(')')[0].split(' ')[0]
r=int(r)
except:
r=0
print(r)
[root@master-mysql ~]# cat juniper_input_rate.py
#!/usr/bin/python3
# encoding=utf-8
import paramiko
import sys
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
argv1=sys.argv[1]
# connect to client
client.connect('192.168.2.2',22,'username','password',allow_agent=False,look_for_keys=False)
#stdin, stdout, stderr = client.exec_command('show interface ge-0/0/1')
stdin, stdout, stderr = client.exec_command('show interface '+argv1)
result = stdout.read().decode()
client.close()
try:
for i in result.splitlines():
if 'Input rate' in i :
r=i.split('(')[1].split(')')[0].split(' ')[0]
r=int(r)
except:
r=0
print(r)
[root@master-mysql ~]# cat /etc/zabbix/zabbix_agentd.conf
###其他内容省略
Timeout=30
UnsafeUserParameters=1
UserParameter=juniper_pps.10102002, /root/juniper.py
UserParameter=juniper_in_pps[*], /root/juniper_input_rate.py "$1"
UserParameter=juniper_out_pps[*], /root/juniper_output_rate.py "$1"
[root@master-mysql ~]# systemctl restart zabbix-agent
可以配置模板,然后关联主机,这里我直接再主机上添加,不配置模板
对此规则设置监控项原型
这步可不做,添加图形