changes for 3.0
[monitor.git] / mailmonitor.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 database
10
11 import rt
12 import sys
13
14 import plc
15 api = plc.getAuthAPI()
16
17 from clean_policy import *
18
19 def reboot(hostname):
20         print "CALLING: mailmonitor.reboot(%s)" % hostname
21
22         l_nodes = api.GetNodes(hostname)
23         if len(l_nodes) == 0:
24                 raise Exception("No such host: %s" % hostname)
25         
26         l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
27         l_ticket_blacklist = database.if_cached_else(1,"l_ticket_blacklist",lambda : [])
28
29         l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
30         if len(l_nodes) == 0:
31                 raise Exception("Host removed via blacklist: %s" % hostname)
32
33         #ad_dbTickets = database.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : [])
34         #if ad_dbTickets == None:
35         #       raise Exception("Could not find cached dbTickets")
36
37         #print "starting new thing"
38         mon = MonitorMergeDiagnoseSendEscellate(hostname, True)
39         mon.run()
40
41         #print "merge"
42         #merge = Merge( [node['hostname'] for node in l_nodes])
43         #record_list = merge.run()
44         ##print "rt"
45         #rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
46         #record_list = rt.run()
47         ##print "diagnose"
48         #diag = Diagnose(record_list)
49         #diagnose_out = diag.run()
50         #print diagnose_out
51         #print "action"
52         #action = Action(diagnose_out)
53         #action.run()
54
55         return True
56
57 #def reboot2(hostname):
58 #       l_nodes = api.GetNodes(hostname)
59 #       if len(l_nodes) == 0:
60 #               raise Exception("No such host: %s" % hostname)
61 #       
62 #       l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
63 #       l_ticket_blacklist = database.if_cached_else(1,"l_ticket_blacklist",lambda : [])
64 #
65 #       l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
66 #       if len(l_nodes) == 0:
67 #               raise Exception("Host removed via blacklist: %s" % hostname)
68 #
69 #       ad_dbTickets = database.if_cached_else_refresh(True, False, "ad_dbTickets", lambda : None)
70 #       if ad_dbTickets == None:
71 #               raise Exception("Could not find cached dbTickets")
72 #
73 #
74 #       args = {}
75 #       args['hostname'] = "%s" % hostname
76 #       args['hostname_list'] = "%s" % hostname
77 #       args['loginbase'] = plc.siteId(hostname)
78 #
79 #       m = PersistMessage(hostname, "Please Update Boot Image for %s" % hostname,
80 #                                                       mailtxt.newalphacd_one[1] % args, True, db='bootcd_persistmessages')
81 #       
82 #       #print "merge"
83 #       merge = Merge( [node['hostname'] for node in l_nodes])
84 #       record_list = merge.run()
85 #       #print "rt"
86 #       rt = RT(record_list, ad_dbTickets, l_ticket_blacklist)
87 #       record_list = rt.run()
88 #       #print "diagnose"
89 #       diag = Diagnose(record_list)
90 #       diagnose_out = diag.run()
91 #       #print diagnose_out
92 #       #print "action"
93 #       action = Action(diagnose_out)
94 #       action.run()
95 #
96 #       return True
97
98
99 def main():
100         for host in sys.argv[1:]:
101                 reboot(host)
102
103 if __name__ == '__main__':
104         print "calling main"
105         main()