监控redis和zookpeer服务脚本 并且python发送邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了监控redis和zookpeer服务脚本 并且python发送邮件相关的知识,希望对你有一定的参考价值。
监控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])
本文出自 “奋斗吧” 博客,转载请与作者联系!
以上是关于监控redis和zookpeer服务脚本 并且python发送邮件的主要内容,如果未能解决你的问题,请参考以下文章