9 from datetime import datetime, timedelta
14 from monitor.model import *
15 from nodecommon import *
17 def get_filefromglob(d, str):
20 # TODO: This is aweful.
22 archive = database.SPickle(path)
23 glob_str = "%s*.%s.pkl" % (d.strftime("%Y-%m-%d"), str)
26 #file = glob.glob(glob_str)[0]
27 files = glob.glob(glob_str)
28 #print "loading %s" % file
30 files_chng = [ file[:-4] for file in files ]
32 #fb = archive.load(file[:-4])
35 def fb_print_nodeinfo(fbnode, verbose, date=None):
36 if verbose: print " state | ssh | pcu | bootcd | category | kernel"
37 if 'checked' in fbnode:
38 print "%11.11s " % diff_time(fbnode['checked']),
41 else: print "Unknown",
44 fbnode['bootcd'] = fbnode['bootcd'].split()[-1]
46 fbnode['bootcd'] = "unknown"
47 fbnode['state'] = color_boot_state(get_current_state(fbnode))
48 fbnode['boot_state'] = getvalue(fbnode, 'plcnode/boot_state')
49 if len(fbnode['kernel'].split()) >= 3:
50 fbnode['kernel'] = fbnode['kernel'].split()[2]
51 print " %(state)5s | %(boot_state)s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
53 def pcu_print_info(pcuinfo, hostname):
55 if 'checked' in pcuinfo:
56 print "%11.11s " % diff_time(pcuinfo['checked'])
60 print "\t user | password | port | hostname "
61 print "\t %17s | %17s | %4s | %30s | %s" % \
62 (pcuinfo['username'], pcuinfo['password'],
63 pcuinfo[hostname], reboot.pcu_name(pcuinfo), pcuinfo['model'])
65 if 'portstatus' in pcuinfo and pcuinfo['portstatus'] != {}:
66 if pcuinfo['portstatus']['22'] == "open":
67 print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo))
68 if pcuinfo['portstatus']['23'] == "open":
69 print "\t telnet %s" % (reboot.pcu_name(pcuinfo))
70 if pcuinfo['portstatus']['80'] == "open" or \
71 pcuinfo['portstatus']['443'] == "open":
72 print "\t http://%s" % (reboot.pcu_name(pcuinfo))
73 if pcuinfo['portstatus']['443'] == "open":
74 print "\t racadm.py -r %s -u %s -p '%s'" % (pcuinfo['ip'], pcuinfo['username'], pcuinfo['password'])
75 print "\t cmdhttps/locfg.pl -s %s -f iloxml/Reset_Server.xml -u %s -p '%s' | grep MESSAGE" % \
76 (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password'])
79 import parser as parsermodule
81 parser = parsermodule.getParser()
82 parser.set_defaults(node=None, fields='state', fromtime=None)
83 parser.add_option("", "--node", dest="node", metavar="nodename.edu",
84 help="A single node name to add to the nodegroup")
85 parser.add_option("", "--fields", dest="fields", metavar="key",
86 help="Which record field to extract from all files.")
87 parser.add_option("", "--fromtime", dest="fromtime", metavar="YYYY-MM-DD",
88 help="Specify a starting date from which to begin the query.")
89 config = parsermodule.parse_args(parser)
92 archive = database.SPickle(path)
95 begin = config.fromtime
99 if config.node is None and len(config.args) > 0:
100 config.node = config.args[0]
101 elif config.node is None:
102 print "Add a hostname to arguments"
106 d = datetime_fromstr(begin)
107 tdelta = timedelta(1)
113 for file in get_filefromglob(d, "production.findbad"):
114 #file = get_filefromglob(d, "production.findbad")
115 #file = "%s.production.findbad" % d.strftime("%Y-%m-%d")
116 fb = archive.load(file)
117 if config.node in fb['nodes']:
118 fb_nodeinfo = fb['nodes'][config.node]['values']
119 fb_print_nodeinfo(fb_nodeinfo, verbose, d.strftime("%Y-%m-%d"))
124 except KeyboardInterrupt:
127 #import traceback; print traceback.print_exc()
128 print d.strftime("%Y-%m-%d"), "No record"
131 if d > datetime.now(): break
133 if __name__ == "__main__":