12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
建站问答 时间:2024-12-01 19:15:13
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
监控cdn上的页面访问示例:邮件脚本如下:#!/usr/bin/python#coding:utf-8importsmtplibfromemail.mine.textimportMIMETextimportsysmail_host='stmp.163.com'mail_use
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
监控cdn上的页面访问示例:
邮件脚本如下:
#!/usr/bin/python
#coding:utf-8
importsmtplib
fromemail.mine.textimportMIMEText
importsys
mail_host='stmp.163.com'
mail_user='test@163.com'
mail_pass='your_mail_password'
mail_postfix='163.com'
defsend_mail(to_list,subject,content):
me="zabbix监控告警平台"+"<"+mail_user+"@"+mail_postfix+">"
msg=MIMEText(content,'plain','utf-8')
msg['Subject']=subject
msg['From']=me
msg['to']=to_list
try:
s=smtplib:SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
returnTrue
exceptException,e:
printstr(e)
returnFalse
if__name__=="__main__"
send_mail(sys.argv[1],sys.argv[2],sys.argv[3])
参考脚本如下:
#!/bin/bash
#监控所有cdn节点是否正常
#定义收件人邮箱
mail="/usr/local/sbin/mail.py"
mail_user=admin@admin.com
url="http://www.lzxlinux.com/test.php"
s_ip="88.88.88.88"
ipf="/data/cdn_ip.list"
if!whichcurl&>/dev/null
then
yuminstall-ycurl
fi
mycurl()
{
curl--connect-timeout2-x$1:80$url2>/dev/null
}
#定义告警函数
m_mail()
{
log=$1
t_s=`date+%s`
t_s2=`date-d"1hoursago"+%s`
if[!-f/tmp/$log]
then
touch/tmp/$log
chattr+a/tmp/$log
echo$t_s2>>/tmp/$log
fi
t_s2=`tail-1/tmp/$log|awk'{print$1}'
echo$t_s>>/tmp/$log
v=$[$t_s-$t_s2]
if[$v-gt1800]
then
python$mail$mail_user"节点$1异常""`cat$2`"2>/dev/null
echo"0">/tmp/$log.count
else
if[!-f/tmp/$log.count]
then
echo"0">/tmp/$log.count
fi
nu=`cat/tmp/$log.count`
nu2=$[$nu+1]
echo$nu2>/tmp/$log.count
if[$nu2-gt30]
then
python$mail$mail_user"节点$1异常持续30分钟了""`cat$2`"2>/dev/null
echo"0">/tmp/$log.count#第二次告警后计时器归0
fi
fi
}
mycurl$s_ip>/tmp/s.html
foripin`cat$ipf`
do
mycurl$ip>/tmp/$ip.html
#对比源站和节点的页面是否有差异
diff/tmp/s.html/tmp/$ip.html>/tmp/$ip.diff2>/dev/null
n=`wc-l/tmp/$ip.diff|awk'{print$1}'`
if[$n-gt0]
then
m_mail$ip/tmp/$ip.diff
fi
done
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19