Monitor Redis and Zookpeer service scripts and python send mail

Source: Internet
Author: User
Tags nets python script


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.