X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=nodequery.py;fp=nodequery.py;h=4091d2f7a024ab79f98a08167ead09c72b3ed895;hb=8b0bb120a071aa27951eb0bf9435aadd9e1df9ed;hp=0000000000000000000000000000000000000000;hpb=5e7c82cf16a734c4d7346126d9f47724e11fc0a3;p=monitor.git diff --git a/nodequery.py b/nodequery.py new file mode 100755 index 0000000..4091d2f --- /dev/null +++ b/nodequery.py @@ -0,0 +1,88 @@ +#!/usr/bin/python + +import plc +import auth +api = plc.PLC(auth.auth, auth.plc) + +import soltesz +fb = soltesz.dbLoad("findbad") +from nodecommon import * + +import time + +from config import config +from optparse import OptionParser +parser = OptionParser() +parser.set_defaults(node=None, category=None, nodelist=None) +parser.add_option("", "--category", dest="category", metavar="category", + help="List all nodes in the given category") +parser.add_option("", "--nodelist", dest="nodelist", metavar="nodelist.txt", + help="A list of nodes to bring out of debug mode.") +config = config(parser) +config.parse_args() + +def diff_time(timestamp): + now = time.time() + if timestamp == None: + return "unknown" + diff = now - timestamp + # return the number of seconds as a difference from current time. + t_str = "" + if diff < 60: # sec in min. + t = diff + t_str = "%s sec ago" % t + elif diff < 60*60: # sec in hour + t = diff // (60) + t_str = "%s min ago" % int(t) + elif diff < 60*60*24: # sec in day + t = diff // (60*60) + t_str = "%s hours ago" % int(t) + elif diff < 60*60*24*7: # sec in week + t = diff // (60*60*24) + t_str = "%s days ago" % int(t) + elif diff < 60*60*24*30: # approx sec in month + t = diff // (60*60*24*7) + t_str = "%s weeks ago" % int(t) + elif diff > 60*60*24*30: # approx sec in month + t = diff // (60*60*24*7*30) + t_str = "%s months ago" % int(t) + return t_str + + +def fb_print_nodeinfo(fbnode, hostname): + fbnode['hostname'] = hostname + fbnode['checked'] = diff_time(fbnode['checked']) + if fbnode['bootcd']: + fbnode['bootcd'] = fbnode['bootcd'].split()[-1] + else: + fbnode['bootcd'] = "unknown" + fbnode['kernel'] = fbnode['kernel'].split()[2] + fbnode['pcu'] = color_pcu_state(fbnode) + print "%(hostname)-39s | %(checked)11.11s | %(state)10.10s | %(ssh)5.5s | %(pcu)6.6s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode + +if config.nodelist: + nodelist = config.getListFromFile(config.nodelist) +else: + nodelist = fb['nodes'].keys() + + +for node in nodelist: + config.node = node + + if node not in fb['nodes']: + continue + + fb_nodeinfo = fb['nodes'][node]['values'] + + if config.category and \ + 'state' in fb_nodeinfo and \ + config.category == fb_nodeinfo['state']: + + fb_print_nodeinfo(fb_nodeinfo, node) + elif config.nodelist and 'state' in fb_nodeinfo: + fb_print_nodeinfo(fb_nodeinfo, node) + else: + pass + + +