zabbix监控supervisorctl中的服务

1、首先获取supervisorctl status

#!/bin/env python
#_*_ coding:utf-8 _*_

import sys
import os
res = {}
path = '/opt/zabbix/scripts/supervisorctl/'

file1 =os.popen('sudo supervisorctl status')
for line in file1.readlines():
        #获取服务名&服务状态
        ser_name = line.split()[0].strip()
        ser_res = line.split()[1].strip()

        #判断服务运行状态,1为成功,0为失败
        if ser_res == 'RUNNING':
                ser_res = '1'
        else:
                ser_res = '0'
        #aa = path + ser_name
        #file_object =open(aa,'wb')
        #file_object.write(ser_res)
        #file_object.close()
        res[ser_name] = ser_res

user_input = str(sys.argv[1].strip())
print(res[user_input])

2、在zabbix中添加自定义参数

UserParameter=supervisorctl.status[*],python /etc/zabbix/scripts/supervisorctl.py $1

3、默认zabbix的账户没有supervisorctl status执行权限,需要配置zabbix免密sudo

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
zabbix  ALL=(ALL)       NOPASSWD:/usr/bin/supervisorctl

原文出处:51ops -> http://www.51ops.com/?p=131

打赏

如果此文对你有所帮助,请随意打赏鼓励作者^_^