AM nagios/plc2nagios.py
[monitor.git] / nodeconfig.py
1 #!/usr/bin/python
2
3
4 import plc
5 import auth
6 api = plc.PLC(auth.auth, auth.plc)
7
8 from optparse import OptionParser
9 from sets import Set
10
11 from nodecommon import *
12 import soltesz
13
14 def main():
15         from config import config
16         fb = soltesz.dbLoad("findbad")
17
18         parser = OptionParser()
19         parser.set_defaults(nodelist=None,
20                                                 list=False,
21                                                 add=False,
22                                                 notng=False,
23                                                 delete=False,
24                                                 )
25         parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", 
26                                                 help="Use all nodes in the given file for operation.")
27         config = config(parser)
28         config.parse_args()
29
30         # COLLECT nodegroups, nodes and node lists
31         for node in config.args:
32
33                 try:
34                         n = api.GetNodes(node)[0]
35                         #print n
36                         net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
37                         #print net
38
39                         node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
40                         for k in node_keys:
41                                 if 'last' in k:
42                                         print "%15s == %s" % (k, diff_time(n[k]))
43                                 else:
44                                         print "%15s == %s" % (k, n[k])
45
46                         static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
47                         for k in static_keys:
48                                 print "%15s == %s" % (k, net[k])
49
50                         #for k in net.keys():
51                         #       print k, "==" , net[k]
52                 except:
53                         print "Error with %s" % node
54                         import traceback; print traceback.print_exc()
55                         pass
56
57         # commands:
58         if False:
59                 if config.list:
60                         print " ---- Nodes in the %s Node Group ----" % group_str
61                         i = 1
62                         for node in nodelist:
63                                 print "%-2d" % i, 
64                                 print nodegroup_display(node, fb)
65                                 i += 1
66
67                 elif config.add and config.nodegroup:
68                         for node in hostnames:
69                                 print "Adding %s to %s nodegroup" % (node, config.nodegroup)
70                                 api.AddNodeToNodeGroup(node, config.nodegroup)
71
72                 elif config.delete:
73                         for node in hostnames:
74                                 print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
75                                 api.DeleteNodeFromNodeGroup(node, config.nodegroup)
76
77                 else:
78                         print "no other options supported."
79
80 if __name__ == "__main__":
81         try:
82                 main()
83         except IOError:
84                 pass