-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitor.py
More file actions
executable file
·62 lines (55 loc) · 2.13 KB
/
monitor.py
File metadata and controls
executable file
·62 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import parseaddr, formataddr
import logging
import requests
import os
logging.basicConfig(level = logging.INFO,
format = '%(asctime)s %(levelname)-8s %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S')
logger = logging.getLogger('monitor')
sender = 'wy250801860@163.com'
receiver = '2751530389@qq.com'
subject = '兔乖乖服务器down机了!!!'
smtpserver = 'smtp.163.com'
username = 'wy250801860@163.com'
password = 'Fuck250801860'
def sendMail(content):
msg = MIMEText(content.encode('utf-8'),'plain','utf-8') #中文需参数‘utf-8’,单字节字符不需要
msg['Subject'] = Header(subject, 'utf-8')
msg['from'] = sender
msg['to'] = receiver
try:
smtp = smtplib.SMTP()
#smtp.set_debuglevel(1)
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
logger.info('send mail successfully!')
except Exception:
logger.info('send mail failed!')
developUrl = "https://139.224.3.149:5656/"
productUrl = "https://139.224.3.149:8080/"
def checkServerStatus(url):
try:
response = requests.get(url, verify = False)
if response.status_code == 200:
logger.info('check {} is ok!'.format(url))
return True
else:
logger.info('check {} is not ok!'.format(url))
return False
except Exception:
logger.info('check {} is not ok!'.format(url))
return False
if __name__ == '__main__':
if not checkServerStatus(developUrl):
sendMail(u"亲爱的管理员, 开发版服务器({})不可访问了,赶紧去看看吧!".format(developUrl))
os.system('bash /etc/init.d/kaka_test')
if not checkServerStatus(productUrl):
sendMail(u"亲爱的管理员, 正式版服务器({})不可访问了,服务器已经开始重启!".format(productUrl))
os.system(r"bash /etc/init.d/kaka")