-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
executable file
·70 lines (56 loc) · 1.88 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import Skype4Py
def main():
skype = Skype4Py.Skype()
skype.OnMessageStatus = on_message
skype.Attach()
# Wait until user exits
cmd = '';
while not cmd == 'exit':
cmd = raw_input('');
def on_message(message, status):
if status == 'RECEIVED' or status == 'SENT':
process_message(message)
class DebugComponent(object):
def handle(self, msg):
"""Print the message."""
for key in dir(msg):
if not key.startswith('_'):
try:
print "{0:>20}: {1}".format(key, getattr(msg, key))
except:
pass
print '*' * 80
class NagiosNotificationComponent(object):
def __init__(self):
self.subscribers = {}
def handle(self, msg):
"""Print the message."""
body = msg.Body.strip()
if not body.lower().startswith('nagios '):
return
body = body[6:].strip()
print body
if body.lower().startswith('sub'):
self.subscribe(msg.FromHandle)
msg.Chat.SendMessage("You've been subscribed to receive Nagios alerts.")
elif body.lower().startswith('unsub'):
self.unsubscribe(msg.FromHandle)
msg.Chat.SendMessage("You've been unsubscribed from receiving Nagios alerts.")
else:
msg.Chat.SendMessage("Unknown command for Nagios.\nKnown commands:\n - sub: Subscribe to nagios alerts\n - unsub: Unsubscribe from nagios alerts")
return True
def subscribe(self, handle):
self.subscribers[handle] = True
def unsubscribe(self, handle):
del self.subscribers[handle]
components = [
NagiosNotificationComponent(),
DebugComponent(),
]
def process_message(msg):
for component in components:
if component.handle(msg) is True:
return
if __name__ == '__main__':
main()