1、编写agentd端python监控脚本
[root@bj1-10-112-80-11 etc]# cat check_port.py
#!/usr/bin/python
__author__ = 'Yan'
import os
import json
data = {}
tcp_list = []
port_list = []
t = ['2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','6770','7778','7779','2348','10055','10066']
tt = []
command = "sudo netstat -tnlp|egrep -i tcp|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort|uniq"
lines = os.popen(command).readlines()
for line in lines:
port = line.split()
port_list.append(port[0])
for i in port_list:
if i in t:
tt.append(i)
for port in list(set(tt)):
port_dict = {}
port_dict['{#TCP_PORT}'] = port
tcp_list.append(port_dict)
data['data'] = tcp_list
jsonStr = json.dumps(data, sort_keys=True, indent=4)
print jsonStr
2、修改agentd_conf文件,添加一下内容
UnsafeUserParameters=1
UserParameter=tcpportlisten,python /usr/local/zabbix/etc/check_port.py
3、增加zabbix用户免秘钥sudo权限
以上完事重启即可
4、配置zabbix web页面
阅读(2745) | 评论(0) | 转发(0) |