Monitoring Rediszookpeer
#!/bin/bashname= ' cat /etc/salt/minion | grep "^id" | awk ' {print $2} ' Ipaddr= '/sbin/ifconfig | grep "inet addr" | egrep -v "10\.| 127\. " | awk -f ' [: ]+ ' ' {print $4} ' Function checkredis () { ps= "' ps -ef | grep redis-server | grep -v grep | wc -l ' " nets= ' netstat -lntup|grep redis|wc -l ' num= ' Cat /tmp/redis.log ' if [ $ps -lt 1 -o $nets -lt 1 ] then if [ $num -eq 0 ];then echo 1 > /tmp/redis.log python python_email.py "ip addr:${ipaddr} salt-minion:$ {Name} redisd is down " " Problem: redis " fi elif [ $ps -gt 0 -a $nets -gt 0 ] then if [ $num - eq 1 ];then echo 0 > /tmp/redis.log python python_email.py "Ip addr:${ipaddr} salt-minion:${name} redisd is ok " " Ok:redis " fi fi}function checkZk () { ps= ' ps -ef|grep zookeeper|grep -v Grep|wc -l ' nets= ' NETSTAT -LNTUP|GREP JAVA|WC -l ' num= ' Cat /tmp/zookeeper.log ' if [ $ps -lt 1 -o $nets -lt 1 ] then if [ $num -eq 0 ];then echo 1 > /tmp/zookeeper.log python python_email.py "Ip addr:${iPaddr} salt-minion:${name} zookeeperd is down " " Problem: zookeeper " fi elif [ $ps -gt 0 -a $nets -gt 0 ] then if [ $num -eq 1 ];then echo 0 > /tmp/zookeeper.log python python_email.py "ip addr:${ipaddr} Salt-minion:${name} zookeeperd is ok " " Ok:zookeeper " fi &nbSp; fi}checkredis#checkzk
Python script
#!/usr/bin/python# -*- coding: utf-8 -*-import sysdef smtp (File,text): from email.mime.text import MIMEText from email.mime.multipart import mimemultipart import smtplib #加邮件头 msg=mimetext (file,_ charset= ' utf-8 ') to_list=[' [email protected] ', ' [email protected] ', ' [email protected] '] msg[' from '] = ' [email protected] ' msg[' Subject '] = text #发送邮件 try: server = smtplib. SMTP () server.connect (' smtp.exmail.qq.com ') server.login (' [email protected] ', ' xxxxx ') #XXX为用户名, XXXXX is password server.sendmail (msg[' from '],to_list,msg.as_string ()) server.quit () print ' send Success ' except Exception, e: print str (e) if __name__ == ' __main__ ': smtp (Sys.argv[1],sys.argv[2])
This article from the "Struggle Bar" blog, reproduced please contact the author!
Monitor Redis and Zookpeer service scripts and python send mail