clearer names for actions, and infer actions better
[monitor.git] / nagios / actions / escalation.py
1 #!/usr/bin/python
2
3 import time
4 import sys
5 import plc
6
7 def argv_to_dict(argv):
8     """
9         NOTE: very bare-bones, no error checking, will fail easily.
10     """
11     d = {}
12     prev=None
13     for a in argv:
14         if "--" == a[0:2]:
15             prev = a[2:]
16         elif "-" == a[0:1]:
17             prev = a[1:]
18         else:
19             d[prev] = a
20     return d
21
22 def main(f):
23     d = argv_to_dict(sys.argv[1:])
24
25     site = None
26     if 'site' in d:
27         site = d['site'].replace('site-cluster-for-','')
28     else:
29         print "No site specified"
30         sys.exit(1)
31         
32     notificationnumber = 1
33     if 'notificationnumber' in d or 'n' in d:
34         try:
35             notificationnumber = int(d['notificationnumber'])
36         except:
37             notificationnumber = int(d['n'])
38
39     interval = 1
40     if 'interval' in d:
41         interval = int(d['interval'])
42
43     type = None
44     if 'notificationtype' in d:
45         type = d['notificationtype']
46
47     if type == "RECOVERY":
48         f.write("\t   %s %s\n" % (time.time(), "enableSiteSliceCreation(%s)" % site ))
49         f.write("\t   %s %s\n" % (time.time(), "enableSiteSlices(%s)" % site ))
50         #plc.enableSiteSliceCreation(site)
51         #plc.enableSiteSlices(site)
52
53     elif type == "PROBLEM":
54         if notificationnumber <= 3:
55             pass
56         elif notificationnumber <= 6:
57             f.write("\t   %s %s\n" % (time.time(), "removeSiteSliceCreation(%s)" % site ))
58             #plc.removeSiteSliceCreation(site)
59         elif notificationnumber > 6:
60             f.write("\t   %s %s\n" % (time.time(), "removeSiteSliceCreation(%s)" % site ))
61             f.write("\t   %s %s\n" % (time.time(), "suspendSiteSlices(%s)" % site ))
62             #plc.removeSiteSliceCreation(site)
63             #plc.suspendSiteSlices(site)
64
65 if __name__ == '__main__':
66     f = open("/tmp/escalation", 'a')
67     f.write("escalation %s %s\n" % (time.time(), " ".join(sys.argv[1:])))
68     main(f)
69     f.close()