-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_module.py
43 lines (30 loc) · 903 Bytes
/
main_module.py
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
import datetime
import time
from urllib.request import urlopen
from pingdumb.smtp_module import form_msg, send_status_mail
def get_status(url):
try:
f = urlopen(url)
except IOError:
return "IOError: can't connect"
return f.getcode()
def url_type(url):
if "://" not in url:
return "http://" + url
else:
return url
def print_status(status, st):
print(st + " | Status is " + str(status))
def checker(conf):
while(True):
status = get_status(conf["url"])
st = get_strftime()
print_status(status, st)
if status != 200:
msg = form_msg(st + "\nHttp status is " + status, conf["toEmail"])
send_status_mail(conf, msg)
time.sleep(conf['interval'])
def get_strftime():
ts = time.time()
return datetime.datetime.fromtimestamp(ts). \
strftime('%Y-%m-%d %H:%M:%S')