#mysql-slave-check
UserParameter=mysql-slave175,python /home/admin/sbin/cmd.py mysql-slave xx.xx.xx.xx 3306 xxxxxxx
$ cat /home/admin/sbin/cmd.py
#!/bin/env python
#coding:utf-8
import os,sys,json,commands,socket,time
def service_check_cmd(name,ip,port,pwd):
global status
if name == 'redis':
codisCmd="/opt/redis/src/redis-cli -c -h %s -p %s set service_check ping" % (ip,port)
try:
status=commands.getoutput(codisCmd)
if status == 'OK':
return 0
else:
return 1
except:
return 1
elif name == 'mysql-slave':
slaveCmd="/opt/mysql/bin/mysql -udba -p%s -h%s -e 'show slave status\G' | grep -E 'Slave_IO_Running'\|'Slave_SQL_Running' | grep -v 'Slave_SQL_Running_State' | awk '{print $2}' | grep Yes | wc -l" % (pwd,ip)
slavestop="/opt/mysql/bin/mysql -udba -p%s -h%s -e 'start slave;'" % (pwd,ip)
try:
status=commands.getoutput(slaveCmd).split('\n')[1]
if int(status) == 2:
return 0
elif int(status) != 2:
return 1
except:
return 1
print service_check_cmd(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])