标签:erro 邮件 监控 mail sendemail stl ESS subject str
import time
import requests
import smtplib
from email.mime.text import MIMEText
import datetime
def SendEmail(fromAdd,toAdd,subject,text):
_pwd = "Yeer2016@sudai" #授权码
msg = MIMEText(text)
msg["Subject"] = subject
msg["From"] = fromAdd
msg["To"] = toAdd
try:
s = smtplib.SMTP_SSL("smtp.sudaizhijia.com", 465)
s.login(fromAdd, _pwd)
s.sendmail(fromAdd, toAdd, msg.as_string())
s.quit()
print ("Success!")
except smtplib.SMTPException:
print(‘Falied!‘)
from_="tech-report@sudaizhijia.com"
to_ = ["wangdong@sudaizhijia.com"] #收件人地址
subject = "URL报警信息"
# url_list=["http://api.sudaizhijia.com","http://event.fastloan360.com","http://www.qianzhouzhou.com","https://data.sudaizhijia.com","http://uat.data.sudaizhijia.com"] #url地址
url_list=["https://m.1sudai.com/","http://www.qianzhouzhou.com"]
while True:
time.sleep(20)
for i in url_list:
nowTime = datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S‘)
try:
code = requests.get(i).status_code
v = int(code)
time.sleep(2)
if isinstance(v,int):
if v == 200:
pass
else:
text = "%s %s 发出报警,值为:%d 请及时查看状态" %(nowTime,i,v)
for i in to_:
SendEmail(from_, i, subject, text)
except requests.exceptions.ConnectionError as e:
text = "%s %s 发出报警,服务可能挂掉 如果有ssl证书可能证书到期" %(nowTime,i)
for i in to_:
SendEmail(from_, i, subject, text)
标签:erro 邮件 监控 mail sendemail stl ESS subject str
原文地址:https://www.cnblogs.com/wangruwei/p/9454974.html