AM nagios/plc2nagios.py
[monitor.git] / bootcds.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import string
6 import time
7 import soltesz
8 import plc
9
10 bootcds = {}
11
12 def main():
13         global bootcds
14
15         l_nodes = plc.getNodes()
16         d_nodes = {}
17         for host in l_nodes:
18                 h = host['hostname']
19                 d_nodes[h] = host
20
21         bootcds = soltesz.if_cached_else(1, "bootcds", lambda : {})
22         for host in d_nodes:
23                 if not host in bootcds:
24                         ssh = soltesz.SSH('root', host)
25                         val = ssh.runE("F=/mnt/cdrom/bootme/ID;G=/usr/bootme/ID; if [ -f $F ] ; then cat $F ; else cat $G ; fi")
26                         print "%s == %s" % (host, val)
27                         bootcds[host] = val
28                 elif "timed out" in bootcds[host]:
29                         # Call again with a longer timeout!
30                         opts = soltesz.ssh_options
31                         opts['ConnectTimeout'] = '60'
32                         ssh = soltesz.SSH('root', host, opts)
33                         val = ssh.runE("F=/mnt/cdrom/bootme/ID;G=/usr/bootme/ID; if [ -f $F ] ; then cat $F ; else cat $G ; fi")
34                         print "TO: %s == %s" % (host, val)
35                         bootcds[host] = val
36                         
37
38         soltesz.dbDump("bootcds", bootcds)
39         
40 if __name__ == '__main__':
41         import os
42         try:
43                 main()
44         except Exception:
45                 print "Saving data... exitting."
46                 soltesz.dbDump("bootcds", bootcds)
47                 sys.exit(0)