move clean_policy.py into monitor package
[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 monitor.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         mon = MonitorMergeDiagnoseSendEscellate(hostname, True)
34         mon.run()
35
36         return True
37
38 def main():
39         for host in sys.argv[1:]:
40                 reboot(host)
41
42 if __name__ == '__main__':
43         print "calling main"
44         main()