python 根据监控结果发送邮件
2012-08-13 10:04
369 查看
使用gg后,需要监控,自己写个自动发送邮件,这只是个原型!根据从数据库返回的数据结果是1还是2来判断同步情况,
并及时发送邮件并短信通知以及记录日志!
# -*- coding: gb2312 -*-
import re
import pyodbc
import traceback
import decimal
import os, sys
import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = '1364188****@139.com'
receiver = '1364188****@139.com'
subject = '数据同步监控'
smtpserver = 'smtp.139.com'
username = '1364188****'
password = '************'
########判断同步是否正常
guess = int(input("请输入一个整数:\n"))
if guess == 1:
msg = MIMEText('监控正常!','plain','gb2312')#中文需参数‘gb2312’,单字节字符不需要
msg['Subject'] = Header(subject, 'gb2312')
msg['date']=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
smtp = smtplib.SMTP()
smtp.connect('smtp.139.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
logtxt='监控邮件已经在'+msg['date']+'发送成功!'+':同步正常'
smtp.quit()
print (logtxt)
f = open('e:\py\log.txt', 'a')
f.write(logtxt+'\n')
f.close()
print ( '日志:'+logtxt+'记录成功' )
elif guess == 2:
msg = MIMEText('监控异常!','plain','gb2312')#中文需参数‘gb2312’,单字节字符不需要
msg['Subject'] = Header(subject, 'gb2312')
msg['date']=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
smtp = smtplib.SMTP()
smtp.connect('smtp.139.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
logtxt='监控邮件已经在'+msg['date']+'发送成功!'+':同步异常'
smtp.quit()
print (logtxt)
f = open('e:\py\log.txt', 'a')
f.write(logtxt+'\n')
f.close()
print ( '日志:'+logtxt+'记录成功' )
else:
print ('**************输入类型不对,请联系ocpyang!**********************')
并及时发送邮件并短信通知以及记录日志!
# -*- coding: gb2312 -*-
import re
import pyodbc
import traceback
import decimal
import os, sys
import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = '1364188****@139.com'
receiver = '1364188****@139.com'
subject = '数据同步监控'
smtpserver = 'smtp.139.com'
username = '1364188****'
password = '************'
########判断同步是否正常
guess = int(input("请输入一个整数:\n"))
if guess == 1:
msg = MIMEText('监控正常!','plain','gb2312')#中文需参数‘gb2312’,单字节字符不需要
msg['Subject'] = Header(subject, 'gb2312')
msg['date']=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
smtp = smtplib.SMTP()
smtp.connect('smtp.139.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
logtxt='监控邮件已经在'+msg['date']+'发送成功!'+':同步正常'
smtp.quit()
print (logtxt)
f = open('e:\py\log.txt', 'a')
f.write(logtxt+'\n')
f.close()
print ( '日志:'+logtxt+'记录成功' )
elif guess == 2:
msg = MIMEText('监控异常!','plain','gb2312')#中文需参数‘gb2312’,单字节字符不需要
msg['Subject'] = Header(subject, 'gb2312')
msg['date']=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
smtp = smtplib.SMTP()
smtp.connect('smtp.139.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
logtxt='监控邮件已经在'+msg['date']+'发送成功!'+':同步异常'
smtp.quit()
print (logtxt)
f = open('e:\py\log.txt', 'a')
f.write(logtxt+'\n')
f.close()
print ( '日志:'+logtxt+'记录成功' )
else:
print ('**************输入类型不对,请联系ocpyang!**********************')
相关文章推荐
- python 根据监控结果发送邮件
- python 根据监控结果发送邮件
- python 根据监控结果发送邮件
- Python2.7实现监控Linux内存、CPU并发送预警邮件
- [Python]查询mysql导出结果至Excel并发送邮件
- Python实现监控某个服务,服务崩溃发送邮件报告
- python监控网站运行异常并发送邮件的方法
- 利用Python自动监控网站并发送邮件告警的方法
- linux定时监控网络连接,利用python发送邮件
- python监控文件并且发送告警邮件
- python实现监控某个服务 服务崩溃即发送邮件报告
- python 监控进程,结束后发送邮件
- python3.6 监控服务器在线,离线自动发送邮件
- 监控redis和zookpeer服务脚本 并且python发送邮件
- zabbix增加手机短信、邮件监控的注意要点,SSL邮件发送python脚本
- python查询mysql导出结果至Excel并发送邮件
- python实现自动监控网站并发送邮件告警
- python实现自动发送报警监控邮件
- 用python实现监控网站状态,并发送告警邮件