Adding the model for log records
[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
13 import plc
14 import auth
15 api = plc.PLC(auth.auth, auth.plc)
16
17 def reboot(hostname):
18
19         l_nodes = api.GetNodes(hostname)
20         if len(l_nodes) == 0:
21                 raise Exception("No such host: %s" % hostname)
22         
23         l_blacklist = soltesz.if_cached_else(1, "l_blacklist", lambda : [])
24         l_ticket_blacklist = soltesz.if_cached_else(1,"l_ticket_blacklist",lambda : [])
25
26         l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
27         if len(l_nodes) == 0:
28                 raise Exception("Host removed via blacklist: %s" % hostname)
29
30         ad_dbTickets = soltesz.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : None)
31         if ad_dbTickets == None:
32                 raise Exception("Could not find cached dbTickets")
33
34         #print "merge"
35         merge = Merge( [node['hostname'] for node in l_nodes])
36         record_list = merge.run()
37         #print "rt"
38         rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
39         record_list = rt.run()
40         #print "diagnose"
41         diag = Diagnose(record_list)
42         diagnose_out = diag.run()
43         #print diagnose_out
44         #print "action"
45         action = Action(diagnose_out)
46         action.run()
47
48         return True
49
50 def main():
51         pass
52
53 if __name__ == '__main__':
54         main()