监控rediszookpeer
#!/bin/bash name=`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 fi } checkRedis #checkZk
python脚本
#!/usr/bin/python # -*- coding: utf-8 -*- import sys def 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为密码 server.sendmail(msg[‘from‘],to_list,msg.as_string()) server.quit() print ‘发送成功‘ except Exception, e: print str(e) if __name__ == ‘__main__‘: smtp(sys.argv[1],sys.argv[2])
时间: 2024-10-13 12:31:54