updated module import statements. not sure how I missed these before.
[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 sys
10
11 from monitor import database
12 from monitor.wrapper import rt
13 from monitor.wrapper import plc
14 from monitor.policy import *
15
16 api = plc.getAuthAPI()
17
18 def reboot(hostname):
19         print "CALLING: mailmonitor.reboot(%s)" % hostname
20
21         l_nodes = api.GetNodes(hostname)
22         if len(l_nodes) == 0:
23                 raise Exception("No such host: %s" % hostname)
24         
25         l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
26         l_ticket_blacklist = database.if_cached_else(1,"l_ticket_blacklist",lambda : [])
27
28         l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
29         if len(l_nodes) == 0:
30                 raise Exception("Host removed via blacklist: %s" % hostname)
31
32         mon = MonitorMergeDiagnoseSendEscellate(hostname, True)
33         mon.run()
34
35         return True
36
37 def main():
38         for host in sys.argv[1:]:
39                 reboot(host)
40
41 if __name__ == '__main__':
42         print "calling main"
43         main()