The use of GG, need to monitor, their own write an automatic mail, this is just a prototype! According to the data returned from the database results are 1 or second to determine the synchronization situation,
and timely send mail and SMS notification and log!
#-*-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 = ' Data Synchronization monitoring '
SmtpServer = ' smtp.139.com '
Username = ' 1364188**** '
Password = ' ************ '
####### #判断同步是否正常
guess = Int (input ("Please enter an integer: \ n"))
If guess = 1:
msg = Mimetext (' Monitor normal! ', ' plain ', ' gb2312 ') #中文需参数 ' gb2312 ', single-byte characters do not need
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= ' monitor Mail has been sent in ' +msg[' Date ']+ ' successfully! ' + ': Sync normal '
Smtp.quit ()
Print (Logtxt)
f = open (' E:\py\log.txt ', ' a ')
F.write (logtxt+ ' \ n ')
F.close ()
Print (' log: ' +logtxt+ ' record successful ')
Elif guess = = 2:
msg = Mimetext (' Monitor exception! ', ' plain ', ' gb2312 ') #中文需参数 ' gb2312 ', single-byte characters do not need
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= ' monitor Mail has been sent in ' +msg[' Date ']+ ' successfully! ' + ': Sync exception '
Smtp.quit ()
Print (Logtxt)
f = open (' E:\py\log.txt ', ' a ')
F.write (logtxt+ ' \ n ')
F.close ()
Print (' log: ' +logtxt+ ' record successful ')
Else
Print (' ************** input type is wrong, please contact ocpyang!********************** ')