[root@localhost checksalt]# cat checkSalt.sh #!/bin/sh rm -f *.txt salt-key -y -A salt-key -L |egrep -v 'Keys|192.168' > saltid.txt salt '*' test.ping > saltTrue.txt > saltid_ok.txt > saltid_fail.txt function checksalt(){ for n in `cat $1` do #echo "grep $n saltTrue.txt " if grep $n saltTrue.txt then echo $n >> saltid_ok.txt else for m in `seq 3` do num=`salt $n cmd.run "ifconfig"|wc -l ` if [ $num -eq 0 ] then sleep 5 if [ $m -eq 3 ] then salt-key -y -d $n echo $n >> saltid_fail.txt fi else continue fi done fi done } checksalt saltid.txt salt-key -L |egrep -v 'Keys|192.168' > saltid_now.txt sh diff_salt_ipcsv.sh [root@localhost ####################################################################### ####################################################################### [root@localhost checksalt]# cat diff_salt_ipcsv.sh #!/bin/sh >have_salt_id.txt >noneed.ip.txt >unconnect_salt_id.txt awk -F'[" "]' '{print $4 " " $14 " "$16}' ip.csv >hangld.ip.csv.txt for n in `awk '{print $2}' hangld.ip.csv.txt` do if grep $n saltid_now.txt then grep $n hangld.ip.csv.txt >>have_salt_id.txt else for m in `cat NoNeed.ip` do #echo "------------>> if $m -eq $n " if [ "$m" == "$n" ] then grep $n hangld.ip.csv.txt >>noneed.ip.txt break fi done grep $n hangld.ip.csv.txt >>unconnect_salt_id.txt fi done diff unconnect_salt_id.txt noneed.ip.txt |awk 'NR>1{print $2 " " $3}' > PROBLEM.txt if [ -s PROBLEM.txt ] then time=`date` python python_email.py "salt_客户端__$time" PROBLEM.txt fi[root@localhost ####################################################################### ####################################################################### [root@localhost checksalt]# cat python_email.py #!/usr/bin/python # -*- coding: utf-8 -*- import sys def smtp(title,file): import smtplib from email.mime.text import MIMEText from email.header import Header with open(file, 'r') as f: content = f.read() #加邮件头 msg=MIMEText(content,'plain', 'utf-8') to_list=['XXX1@qq.com',XXX2@qq.com] msg['from'] = 'XXX@qq.com' msg['subject'] = title #发送邮件 try: server = smtplib.SMTP() server.connect('smtp.exmail.qq.com') server.login('XXX@qq.com','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]) [root@localhost checksalt]# ####################################################################### ####################################################################### [root@localhost checksalt]# crontab -l */10 * * * * /bin/sh /script/shell/gaogd/checksalt/checkSalt.sh >/dev/null 2>&1 [root@localhost checksalt]#
编写定时监控salt和客户端之间的通信状态并发邮件报警----- saltstack
原创
©著作权归作者所有:来自51CTO博客作者lvnian2009的原创作品,谢绝转载,否则将追究法律责任
上一篇:学习网址
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章