zabbix的日常监控-自动发现端口并监测(服务器开启的所有端口或监控指定端口)(十三)...
生活随笔
收集整理的這篇文章主要介紹了
zabbix的日常监控-自动发现端口并监测(服务器开启的所有端口或监控指定端口)(十三)...
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
動(dòng)批量檢查agent開(kāi)放的端口
注:此方法給監(jiān)控磁盤IO(即十二)篇過(guò)程一樣;
注釋:如果服務(wù)器上的應(yīng)用都是固定的,不會(huì)隨機(jī)產(chǎn)生的都可以使用自動(dòng)發(fā)現(xiàn)端口來(lái)監(jiān)控;
?如果服務(wù)器會(huì)隨機(jī)出現(xiàn)端口且每次啟動(dòng)程序都會(huì)改變,可以采用第二種方法,來(lái)監(jiān)控指定的端口;
?
約定:
zabbix所有執(zhí)行的腳本統(tǒng)一放置在?/etc/zabbix/scripts 目錄下
chown root:zabbix -R /etc/zabbix/scripts/ chmod 750 /etc/zabbix/scripts/ chmod 550 /etc/zabbix/scripts/iostat.sh一、agent操作:
1、腳本內(nèi)容
[root@agent scripts]# cat check_port1.sh #!/usr/bin/env python #coding:utf-8 import os, json port_list=[] port_dict={"data":None} cmd='''''netstat -tnlp|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort |uniq 2>/dev/null''' local_ports=os.popen(cmd).readlines() for port in local_ports: pdict={} pdict["{#TCP_PORT}"]=port.replace("\n", "") port_list.append(pdict) port_dict["data"]=port_list jsonStr = json.dumps(port_dict, sort_keys=True, indent=4) print jsonStr [root@agent scripts]#[root@agent scripts]#chmod +s /usr/bin/netstat
2、添加key值
cat /etc/zabbix/zabbix_agentd.conf 添加如下內(nèi)容: UnsafeUserParameters=1 UserParameter=tcpportlisten,/etc/zabbix/scripts/check_port1.sh?
3、重啟agent服務(wù)
systemctl restart zabbix-agent.service?
?
二、zabbix-server端操作
1、創(chuàng)建模板:Template Ports Discovery
2、創(chuàng)建自動(dòng)發(fā)現(xiàn)規(guī)則
?3、創(chuàng)建監(jiān)控項(xiàng)原型
?
?
?4、創(chuàng)建圖形原型
?
?5、創(chuàng)建觸發(fā)器
此方法可以批量為多個(gè)監(jiān)控端口添加相同的閾值!!!
?
?
?三、結(jié)果
?
?
?
監(jiān)控指定端口范圍內(nèi)的端口
原博文地址:http://blog.chinaunix.net/uid-29680017-id-5768335.html
1、腳本內(nèi)容
[root@agent scripts]#vim prot.py #!/usr/bin/python __author__ = 'Yan' import os import jsondata = {} tcp_list = [] port_list = [] t = ['3306','8080','2002','2003','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}'] = porttcp_list.append(port_dict)data['data'] = tcp_list jsonStr = json.dumps(data, sort_keys=True, indent=4) print jsonStr?
?2、執(zhí)行結(jié)果
?
轉(zhuǎn)載于:https://www.cnblogs.com/huangyanqi/p/9076153.html
總結(jié)
以上是生活随笔為你收集整理的zabbix的日常监控-自动发现端口并监测(服务器开启的所有端口或监控指定端口)(十三)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Oracle Client安装报错:引用
- 下一篇: ls 命令还能这么玩?看一下这 20 个