(no commit message)
[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 from monitor.database.info.model import *
16
17 api = plc.getAuthAPI()
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         q_blacklist = BlacklistRecord.query.all()
27
28         l_blacklist = [ n.hostname for n in q_blacklist ]
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()