3 from config import config
4 from optparse import OptionParser
5 from www.printbadnodes import *
9 db = database.dbLoad(config.dbname)
10 fb = database.dbLoad("findbadpcus")
11 act= database.dbLoad("act_all")
13 ## Field widths used for printing
14 maxFieldLengths = { 'nodename' : -45,
25 ## create format string based on config.fields
28 for f in config.fields.split(','):
29 fields[f] = "%%(%s)%ds" % (f, maxFieldLengths[f])
30 for f in config.fields.split(','):
31 format += fields[f] + " "
36 l_nodes = sys.argv[2:]
40 # d2 was an array of [{node}, {}, ...]
41 # the bysite is a loginbase dict of [{node}, {node}]
43 for nodename in l_nodes:
44 vals=d_n[nodename]['values']
47 v['nodename'] = nodename
48 if 'plcsite' in vals and 'status' in vals['plcsite'] and vals['plcsite']['status'] == "SUCCESS":
49 site_string = "<b>%-20s</b> %2s nodes :: %2s of %4s slices" % ( \
50 vals['plcsite']['login_base'],
51 vals['plcsite']['num_nodes'],
52 vals['plcsite']['num_slices'],
53 vals['plcsite']['max_slices'])
54 v['site_string'] = site_string
57 #print "ERROR: ", nodename, vals, "<br>"
59 #site_string = "<b>UNKNOWN</b>"
66 elif config.cmpcategory:
67 d2.sort(cmp=cmpCategory)
72 elif config.cmpkernel:
75 d2.sort(cmp=cmpCategory)
79 site_string = row['site_string']
81 # convert uname values into a single kernel version string
83 kernel = vals['kernel'].split()
85 if kernel[0] == "Linux":
86 vals['kernel'] = kernel[2]
88 vals['ssherror'] = vals['kernel']
95 if 'pcu' in vals and vals['pcu'] == "PCU":
96 # check the health of the pcu.
97 s = pcu_state(vals['plcnode']['pcu_ids'][0])
99 vals['pcu'] = "UP-PCU"
101 vals['pcu'] = "DN-PCU"
104 if vals['nodename'] in act:
105 if len(act[vals['nodename']]) > 0 and 'rt' in act[vals['nodename']][0]:
106 if 'Status' in act[vals['nodename']][0]['rt']:
107 vals['rt'] = "%s %s" % (act[vals['nodename']][0]['rt']['Status'],
108 act[vals['nodename']][0]['rt']['id'])
113 s = fields_to_html(fields, vals)
118 keys = categories.keys()
119 for cat in ['BOOT-ALPHA', 'BOOT-PROD', 'BOOT-OLDBOOTCD', 'DEBUG-ALPHA',
120 'DEBUG-PROD', 'DEBUG-OLDBOOTCD', 'DOWN-ERROR']:
123 keys = categories.keys()
124 for cat in ['BOOT-ALPHA', 'BOOT-PROD', 'BOOT-OLDBOOTCD', 'DEBUG-ALPHA',
125 'DEBUG-PROD', 'DEBUG-OLDBOOTCD', 'DOWN-ERROR']:
127 print "%d," % categories[cat],
130 if __name__ == '__main__':
131 parser = OptionParser()
132 parser.set_defaults(cmpdays=False,
134 fields="nodename,ping,ssh,pcu,category,state,kernel,bootcd,rt",
135 dbname="findbad", # -070724-1",
141 parser.add_option("", "--fields", dest="dbname", help="")
142 parser.add_option("", "--dbname", dest="dbname", help="")
143 parser.add_option("", "--display", dest="display", action="store_true")
144 parser.add_option("", "--days", dest="cmpdays", action="store_true", help="")
145 parser.add_option("", "--ping", dest="cmpping", action="store_true", help="")
146 parser.add_option("", "--ssh", dest="cmpssh", action="store_true", help="")
147 parser.add_option("", "--category", dest="cmpcategory", action="store_true", help="")
148 parser.add_option("", "--kernel", dest="cmpkernel", action="store_true", help="")
149 parser.add_option("", "--state", dest="cmpstate", action="store_true", help="")
150 parser.add_option("", "--comon", dest="comon", help="")
151 config = config(parser)