1.編輯掃描端口腳本,存放在/usr/local/zabbix/scripts/lll.py
#!/usr/bin/python
__author__ = 'Yan'
import os
import json
data = {}
tcp_list = []
port_list = []
command = 'netstat -notl| tail -n +3'
lines = os.popen(command).readlines()
for line in lines:
port = line.split()[3].split(':')[1]
port_list.append(port)
for port in list(set(port_list)):
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.配置zabbix-agentd.conf添加以下內容
UserParameter=TcpPortListen,python /usr/local/zabbix/script/lll.py |tail -n +3
3.測試
這個時候在zabbix_server端就可以用zabbix_get來測試是否正常。
zabbix_get -s ip -k TcpPortListen
4.配置頁面
配置discovery
添加items
添加trigger,然後查看監控items,是否會自動增加
感謝支持:http://www.linuxyan.com/cacti-nagios/396.html