merges from v2
[monitor.git] / dumpact.py
1 #!/usr/bin/python
2
3 # Read in the act_* databases and print out a human readable version
4
5 import sys
6 import time
7 import getopt
8 import database 
9 from monitor.wrapper import plccache
10
11 def main():
12
13         act_all = database.dbLoad(sys.argv[1])
14         plcdb_hn2lb = plccache.plcdb_hn2lb
15         s_nodenames = ""
16         sickdb = {}
17
18         sorted_keys = act_all.keys()
19         sorted_keys.sort()
20         for nodename in sorted_keys:
21                 diag_nodelist = act_all[nodename]
22                 if nodename in plcdb_hn2lb:
23                         lb = plcdb_hn2lb[nodename]
24                         if lb not in sickdb:
25                                 sickdb[lb] = {}
26                         sickdb[lb][nodename] = diag_nodelist
27
28         sorted_keys = sickdb.keys()
29         sorted_keys.sort()
30         for loginbase in sorted_keys:
31                 nodedict = sickdb[loginbase]
32                 sort_nodekeys = nodedict.keys()
33                 sort_nodekeys.sort()
34                 print "%s :" % loginbase
35                 for nodename in sort_nodekeys:
36                         if len(act_all[nodename]) == 0:
37                                 print "%20s : %-40s has no events" % (loginbase, nodename)
38                         else:
39                                 l_ev = act_all[nodename]
40                                 print "    %s" % nodename
41                                 for diag_node in l_ev:
42                                         keys = diag_node.keys()
43                                         keys.sort()
44                                         for k in keys:
45                                                 if "message" not in k and "msg" not in k:
46                                                         if 'time' in k:
47                                                                 s_time=time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(diag_node[k]))
48                                                                 print "\t'%s' : %s" % (k, s_time)
49                                                         else:
50                                                                 print "\t'%s' : %s" % (k, diag_node[k])
51                                         print "\t--"
52
53         print s_nodenames
54
55         
56 if __name__ == '__main__':
57         main()