Zabbix+Python自动发现进程端口和进程名称
2018-09-21 14:57
1721 查看
Python脚本
运行结果如下
#!/usr/bin/env python #coding=utf-8 #Debug in Python2.7 #used for discovery the Listen Port and Process #Author wangshisheng 20180602 import os import json import string t = os.popen(""" sudo ss -tunlp |grep LISTEN |sed "s#::#FF#g" |grep users |sort |uniq """) array = [] for port in t.readlines(): r=port.strip() #print r port = r.split(':')[1].split(' ')[0] try: name = r.split('\"')[1] except: name = "none" cluster = {} cluster['{#TCP_PORT}'] = port cluster['{#TCP_NAME}'] = name array.append(cluster) #amy = [{k:v} for k,v in dict([list(d.iteritems())[0] for d in array]).iteritems()] amy = [dict(t) for t in set([tuple(d.items()) for d in array])] print json.dumps({'data':amy},sort_keys=True,indent=4,separators=(',',':'))
运行结果如下
{ "data":[ { "{#TCP_NAME}":"srv.User.plus", "{#TCP_PORT}":"6049" }, { "{#TCP_NAME}":"zabbix_agentd", "{#TCP_PORT}":"10050" } ] }
相关文章推荐
- Zabbix之Python脚本端口自动发现
- zabbix 自动发现 python
- zabbix添加自动发现端口,提示Value should be a JSON object.
- zabbix自动发现mysql端口并监控
- Zabbix实现自动发现端口并监控
- Zabbix使用自动发现功能监控服务器各JVM进程状态
- ZABBIX自动发现端口监控
- zabbix通过自动发现tomcat应用端口监控连接数
- zabbix自动发现端口
- 分布式监控系统Zabbix--完整安装记录-批量添加主机和自动发现端口
- Zabbix低级发现结合jstat命令自动监控Java进程(jdk 1.8版本)
- zabbix自动发现监控远程端口
- zabbix自动发现端口并监控
- zabbix自动发现规则实现批量监控主机的TCP监听端口
- zabbix自动发现结合shell实现自动发现占用内存最大top10进程并监控其资源 推荐
- Zabbix监控之Redis自动发现并监控(python)
- zabbix自动发现mysql端口并监控
- zabbix自动发现主机服务端口
- zabbix自动发现使用中端口并图形展示各个端口连接数
- zabbix自动发现与监控内存和CPU使用率最高的进程