Tagging module Monitor - Monitor-1.0-5
[monitor.git] / monitor.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2004  The Trustees of Princeton University (Trustees).
4
5 # Stephen Soltesz <soltesz@cs.princeton.edu>
6 #
7 # $Id: monitor.py,v 1.7 2007/07/03 19:59:02 soltesz Exp $
8
9 import soltesz
10
11 from monitor_policy import *
12 import rt
13
14 import plc
15 import auth
16 api = plc.PLC(auth.auth, auth.plc)
17
18 def reboot(hostname):
19
20         l_nodes = api.GetNodes(hostname)
21         if len(l_nodes) == 0:
22                 raise Exception("No such host: %s" % hostname)
23         
24         l_blacklist = soltesz.if_cached_else(1, "l_blacklist", lambda : [])
25         l_ticket_blacklist = soltesz.if_cached_else(1,"l_ticket_blacklist",lambda : [])
26
27         l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
28         if len(l_nodes) == 0:
29                 raise Exception("Host removed via blacklist: %s" % hostname)
30
31         ad_dbTickets = soltesz.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : [])
32         if ad_dbTickets == None:
33                 raise Exception("Could not find cached dbTickets")
34
35         #print "merge"
36         merge = Merge( [node['hostname'] for node in l_nodes])
37         record_list = merge.run()
38         #print "rt"
39         rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
40         record_list = rt.run()
41         #print "diagnose"
42         diag = Diagnose(record_list)
43         diagnose_out = diag.run()
44         #print diagnose_out
45         #print "action"
46         action = Action(diagnose_out)
47         action.run()
48
49         return True
50
51 def reboot2(hostname):
52         l_nodes = api.GetNodes(hostname)
53         if len(l_nodes) == 0:
54                 raise Exception("No such host: %s" % hostname)
55         
56         l_blacklist = soltesz.if_cached_else(1, "l_blacklist", lambda : [])
57         l_ticket_blacklist = soltesz.if_cached_else(1,"l_ticket_blacklist",lambda : [])
58
59         l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
60         if len(l_nodes) == 0:
61                 raise Exception("Host removed via blacklist: %s" % hostname)
62
63         ad_dbTickets = soltesz.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : None)
64         if ad_dbTickets == None:
65                 raise Exception("Could not find cached dbTickets")
66
67
68         args = {}
69         args['hostname'] = "%s" % hostname
70         args['hostname_list'] = "%s" % hostname
71         args['loginbase'] = plc.siteId(hostname)
72
73         m = PersistMessage(hostname, "Please Update Boot Image for %s" % hostname,
74                                                         mailtxt.newalphacd_one[1] % args, True, db='bootcd_persistmessages')
75         
76         #print "merge"
77         merge = Merge( [node['hostname'] for node in l_nodes])
78         record_list = merge.run()
79         #print "rt"
80         rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
81         record_list = rt.run()
82         #print "diagnose"
83         diag = Diagnose(record_list)
84         diagnose_out = diag.run()
85         #print diagnose_out
86         #print "action"
87         action = Action(diagnose_out)
88         action.run()
89
90         return True
91
92
93 def main():
94         pass
95
96 if __name__ == '__main__':
97         main()