-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaammonit.py
57 lines (43 loc) · 1.33 KB
/
aammonit.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# import logging
from time import sleep
import config
class Aammonit(object):
def __init__(self, config):
self.config = config
self.states = []
def start(self):
while True:
self.check_services()
def stop(self):
for notifier in self.config.to_notify:
notifier.terminate()
def notify(self, message):
for notifier in config.to_notify:
notifier.send_notification(message)
def check_services(self):
for service in self.config.to_check:
try:
if service.online():
if str(service) in self.states:
self.states.remove(str(service))
self.notify(str(service) + " is now back online.")
else:
if str(service) in self.states:
pass
else:
self.states.append(str(service))
self.notify(service.status())
except Exception as e:
self.notify(str(e))
sleep(self.config.interval)
if __name__ == '__main__':
am = Aammonit(config)
try:
am.start()
except KeyboardInterrupt:
am.stop()
except:
am.stop()
raise