2 from monitor import database
3 from monitor import config
4 import parser as parsermodule
6 from www.printbadnodes import *
10 db = database.dbLoad(config.dbname)
11 fb = database.dbLoad("findbadpcus")
12 act= database.dbLoad("act_all")
14 ## Field widths used for printing
15 maxFieldLengths = { 'nodename' : -45,
26 ## create format string based on config.fields
29 for f in config.fields.split(','):
30 fields[f] = "%%(%s)%ds" % (f, maxFieldLengths[f])
31 for f in config.fields.split(','):
32 format += fields[f] + " "
37 l_nodes = sys.argv[2:]
41 # d2 was an array of [{node}, {}, ...]
42 # the bysite is a loginbase dict of [{node}, {node}]
44 for nodename in l_nodes:
45 vals=d_n[nodename]['values']
48 v['nodename'] = nodename
49 if 'plcsite' in vals and 'status' in vals['plcsite'] and vals['plcsite']['status'] == "SUCCESS":
50 site_string = "<b>%-20s</b> %2s nodes :: %2s of %4s slices" % ( \
51 vals['plcsite']['login_base'],
52 vals['plcsite']['num_nodes'],
53 vals['plcsite']['num_slices'],
54 vals['plcsite']['max_slices'])
55 v['site_string'] = site_string
58 #print "ERROR: ", nodename, vals, "<br>"
60 #site_string = "<b>UNKNOWN</b>"
67 elif config.cmpcategory:
68 d2.sort(cmp=cmpCategory)
73 elif config.cmpkernel:
76 d2.sort(cmp=cmpCategory)
80 site_string = row['site_string']
82 # convert uname values into a single kernel version string
84 kernel = vals['kernel'].split()
86 if kernel[0] == "Linux":
87 vals['kernel'] = kernel[2]
89 vals['ssherror'] = vals['kernel']
96 if 'pcu' in vals and vals['pcu'] == "PCU":
97 # check the health of the pcu.
98 s = pcu_state(vals['plcnode']['pcu_ids'][0])
100 vals['pcu'] = "UP-PCU"
102 vals['pcu'] = "DN-PCU"
105 if vals['nodename'] in act:
106 if len(act[vals['nodename']]) > 0 and 'rt' in act[vals['nodename']][0]:
107 if 'Status' in act[vals['nodename']][0]['rt']:
108 vals['rt'] = "%s %s" % (act[vals['nodename']][0]['rt']['Status'],
109 act[vals['nodename']][0]['rt']['id'])
114 s = fields_to_html(fields, vals)
119 keys = categories.keys()
120 for cat in ['BOOT-PROD', 'BOOT-OLDPROD', 'BOOT-OLDBOOTCD', 'DEBUG-PROD',
121 'DEBUG-OLDPROD', 'DEBUG-OLDBOOTCD', 'DOWN-ERROR']:
124 keys = categories.keys()
125 for cat in ['BOOT-PROD', 'BOOT-OLDPROD', 'BOOT-OLDBOOTCD', 'DEBUG-PROD',
126 'DEBUG-OLDPROD', 'DEBUG-OLDBOOTCD', 'DOWN-ERROR']:
128 print "%d," % categories[cat],
131 if __name__ == '__main__':
132 parser = parsermodule.getParser()
133 parser.set_defaults(cmpdays=False,
135 fields="nodename,ping,ssh,pcu,category,state,kernel,bootcd,rt",
136 dbname="findbad", # -070724-1",
142 parser.add_option("", "--fields", dest="dbname", help="")
143 parser.add_option("", "--dbname", dest="dbname", help="")
144 parser.add_option("", "--display", dest="display", action="store_true")
145 parser.add_option("", "--days", dest="cmpdays", action="store_true", help="")
146 parser.add_option("", "--ping", dest="cmpping", action="store_true", help="")
147 parser.add_option("", "--ssh", dest="cmpssh", action="store_true", help="")
148 parser.add_option("", "--category", dest="cmpcategory", action="store_true", help="")
149 parser.add_option("", "--kernel", dest="cmpkernel", action="store_true", help="")
150 parser.add_option("", "--state", dest="cmpstate", action="store_true", help="")
151 parser.add_option("", "--comon", dest="comon", help="")
152 config = parsermodule.parse_args(parser)