X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=www%2Fprintbadnodes.py;h=3bfc7bdf8007a22ded4ae65158f59eafcfc43222;hb=944d143a6528c4157b71f51ed480aec806cbaa06;hp=95bddf46cd6a92aee4eca4ebc1a705df38d35729;hpb=c1cdc2dc48f47382c0c7329886598dd1e6bbed1a;p=monitor.git diff --git a/www/printbadnodes.py b/www/printbadnodes.py index 95bddf4..3bfc7bd 100755 --- a/www/printbadnodes.py +++ b/www/printbadnodes.py @@ -1,13 +1,12 @@ #!/usr/bin/python -import soltesz -from config import config -from optparse import OptionParser +from monitor import database +from monitor import config import string - import sys categories = {} ssherror = False +fb = {} def sec2days(sec): if sec == "null": @@ -63,7 +62,7 @@ def cmpState(l1, l2): return cmpMap(l1,l2,'state', map) def cmpCategoryVal(v1, v2): - map = array_to_priority_map([ None, 'ALPHA', 'PROD', 'OLDBOOTCD', 'UNKNOWN', 'ERROR', ]) + map = array_to_priority_map([ None, 'ALPHA', 'PROD', 'OLDBOOTCD', 'UNKNOWN', 'FORCED', 'ERROR', ]) return cmpValMap(v1,v2,map) def cmpCategory(l1, l2): @@ -144,9 +143,32 @@ def ssh_error_to_str(str): return ssh_error +def pcu_state(pcu_id): + global fb + + if 'nodes' in fb and "id_%s" % pcu_id in fb['nodes'] \ + and 'values' in fb['nodes']["id_%s" % pcu_id]: + rec = fb['nodes']["id_%s" % pcu_id]['values'] + if 'reboot' in rec: + rb = rec['reboot'] + if rb == 0 or rb == "0": + return 0 + elif "NetDown" == rb or "Not_Run" == rb: + return 1 + else: + return -1 + else: + return -1 + else: + return -1 + def fields_to_html(fields, vals): global categories global ssherror + pcu_colorMap = { -1 : 'indianred', + 0 : 'darkseagreen', + 1 : 'gold', } + colorMap = { 'PING' : 'darkseagreen', 'NOPING': 'darksalmon', 'SSH': 'darkseagreen', @@ -199,6 +221,10 @@ def fields_to_html(fields, vals): r_str += "%s" % (bgcolor, f) elif f == 'PCU': if len(vals['plcnode']['pcu_ids']) > 0: + #print "pcu_id: %s
" % vals['plcnode']['pcu_ids'][0] + #print "state: %s
" % pcu_state(vals['plcnode']['pcu_ids'][0]) + #print "color: %s
" % pcu_colorMap[pcu_state(vals['plcnode']['pcu_ids'][0])] + bgcolor = "bgcolor='%s'" % pcu_colorMap[pcu_state(vals['plcnode']['pcu_ids'][0])] url = "PCU" % vals['plcnode']['pcu_ids'][0] r_str += "%s" % (bgcolor, url) else: @@ -210,8 +236,11 @@ def fields_to_html(fields, vals): -def main(sitefilter): - db = soltesz.dbLoad(config.dbname) +def main(sitefilter, catfilter, statefilter, comonfilter, nodeonlyfilter): + global fb + + db = database.dbLoad(config.dbname) + fb = database.dbLoad("findbadpcus") ## Field widths used for printing maxFieldLengths = { 'nodename' : -45, @@ -318,12 +347,38 @@ def main(sitefilter): d2.sort(cmp=cmpCategory) + if catfilter != None: cf = re.compile(catfilter) + else: cf = None + + if statefilter != None: stf = re.compile(statefilter) + else: stf = None + + if comonfilter != None: cmf = re.compile(comonfilter) + else: cmf = None + #l_loginbase = bysite.keys() #l_loginbase.sort() - print "" + if nodeonlyfilter == None: + print "
" + prev_sitestring = "" for row in d2: + vals = row + + if (catfilter != None and cf.match(vals['category']) == None): + continue + + if (statefilter != None and stf.match(vals['state']) == None): + continue + + if (comonfilter != None and comonfilter in vals['comonstats'] and vals['comonstats'][comonfilter] != 'null'): + continue + + if nodeonlyfilter != None: + print vals['nodename'] + continue + site_string = row['site_string'] if site_string != prev_sitestring: print "" - print "
" @@ -334,7 +389,7 @@ def main(sitefilter): prev_sitestring = site_string - vals = row + # convert uname values into a single kernel version string if 'kernel' in vals: kernel = vals['kernel'].split() @@ -372,6 +427,10 @@ def main(sitefilter): vals['reboot'] = "%s" % vals['reboot'] vals['reboot'] = vals['reboot'].replace(" ", "_") + if 'nodename' in vals: + url = "%s" % (vals['nodename'], vals['nodename']) + vals['nodename'] = url + try: str_fields = [] count = 0 @@ -386,8 +445,9 @@ def main(sitefilter): print "\n
" - print "" + if nodeonlyfilter == None: + print "
" + print "" keys = categories.keys() keys.sort() for cat in keys: @@ -395,7 +455,8 @@ def main(sitefilter): print "" % cat print "" % categories[cat] print "" - print "
Total %s%s
" + if nodeonlyfilter == None: + print "" @@ -412,34 +473,43 @@ if __name__ == '__main__': myfilter = form.getvalue("site") else: myfilter = None - parser = OptionParser() - parser.set_defaults(cmpdays=False, - comon="sshstatus", - fields="nodename,ping,ssh,pcu,category,state,kernel,bootcd", - dbname="findbad", # -070724-1", - cmpping=False, - cmpdns=False, - cmploginbase=False, - cmpssh=False, - cmpcategory=False, - cmpstate=False) - parser.add_option("", "--fields", dest="fields", help="") - parser.add_option("", "--dbname", dest="dbname", help="") - parser.add_option("", "--days", dest="cmpdays", action="store_true", help="") - parser.add_option("", "--ping", dest="cmpping", action="store_true", help="") - parser.add_option("", "--dns", dest="cmpdns", action="store_true", help="") - parser.add_option("", "--ssh", dest="cmpssh", action="store_true", help="") - parser.add_option("", "--loginbase",dest="cmploginbase",action="store_true", help="") - parser.add_option("", "--category", dest="cmpcategory", action="store_true", help="") - parser.add_option("", "--kernel", dest="cmpkernel", action="store_true", help="") - parser.add_option("", "--state", dest="cmpstate", action="store_true", help="") - parser.add_option("", "--comon", dest="comon", help="") - config = config(parser) - config.parse_args() + + if form.has_key('category'): + mycategory = form.getvalue("category") + else: + mycategory = None + + if form.has_key('state'): + mystate = form.getvalue("state") + else: + mystate = None + + if form.has_key('comon'): + mycomon = form.getvalue("comon") + else: + mycomon = None + + if form.has_key('nodeonly'): + mynodeonly = form.getvalue("nodeonly") + else: + mynodeonly = None + + config.cmpdays=False + config.comon="sshstatus" + config.fields="nodename,ping,ssh,pcu,category,state,comonstats,kernel,bootcd" + config.dbname="findbad" + config.cmpping=False + config.cmpdns=False + config.cmploginbase=False + config.cmpssh=False + config.cmpcategory=False + print "Content-Type: text/html\r\n" - print "\n" + if mynodeonly == None: + print "\n" if len(sys.argv) > 1: if sys.argv[1] == "ssherror": ssherror = True - main(myfilter) - print "\n" + main(myfilter, mycategory, mystate, mycomon,mynodeonly) + if mynodeonly == None: + print "\n"