2 from monitor import database
3 from monitor import config
4 import parser as parsermodule
6 from www.printbadnodes import *
9 db = database.dbLoad(config.dbname)
10 act= database.dbLoad("act_all")
12 ## Field widths used for printing
13 maxFieldLengths = { 'nodename' : -45,
24 ## create format string based on config.fields
27 for f in config.fields.split(','):
28 fields[f] = "%%(%s)%ds" % (f, maxFieldLengths[f])
29 for f in config.fields.split(','):
30 format += fields[f] + " "
35 l_nodes = sys.argv[2:]
39 # d2 was an array of [{node}, {}, ...]
40 # the bysite is a loginbase dict of [{node}, {node}]
42 for nodename in l_nodes:
43 vals=d_n[nodename]['values']
46 v['nodename'] = nodename
47 if 'plcsite' in vals and 'status' in vals['plcsite'] and vals['plcsite']['status'] == "SUCCESS":
48 site_string = "<b>%-20s</b> %2s nodes :: %2s of %4s slices" % ( \
49 vals['plcsite']['login_base'],
50 vals['plcsite']['num_nodes'],
51 vals['plcsite']['num_slices'],
52 vals['plcsite']['max_slices'])
53 v['site_string'] = site_string
56 #print "ERROR: ", nodename, vals, "<br>"
58 #site_string = "<b>UNKNOWN</b>"
65 elif config.cmpcategory:
66 d2.sort(cmp=cmpCategory)
71 elif config.cmpkernel:
74 d2.sort(cmp=cmpCategory)
78 site_string = row['site_string']
80 # convert uname values into a single kernel version string
82 kernel = vals['kernel'].split()
84 if kernel[0] == "Linux":
85 vals['kernel'] = kernel[2]
87 vals['ssherror'] = vals['kernel']
94 if 'pcu' in vals and vals['pcu'] == "PCU":
95 # check the health of the pcu.
96 s = pcu_state(vals['plcnode']['pcu_ids'][0])
98 vals['pcu'] = "UP-PCU"
100 vals['pcu'] = "DN-PCU"
103 if vals['nodename'] in act:
104 if len(act[vals['nodename']]) > 0 and 'rt' in act[vals['nodename']][0]:
105 if 'Status' in act[vals['nodename']][0]['rt']:
106 vals['rt'] = "%s %s" % (act[vals['nodename']][0]['rt']['Status'],
107 act[vals['nodename']][0]['rt']['id'])
112 s = fields_to_html(fields, vals)
117 keys = categories.keys()
118 for cat in ['BOOT-PROD', 'BOOT-OLDPROD', 'BOOT-OLDBOOTCD', 'DEBUG-PROD',
119 'DEBUG-OLDPROD', 'DEBUG-OLDBOOTCD', 'DOWN-ERROR']:
122 keys = categories.keys()
123 for cat in ['BOOT-PROD', 'BOOT-OLDPROD', 'BOOT-OLDBOOTCD', 'DEBUG-PROD',
124 'DEBUG-OLDPROD', 'DEBUG-OLDBOOTCD', 'DOWN-ERROR']:
126 print "%d," % categories[cat],
129 if __name__ == '__main__':
130 parser = parsermodule.getParser()
131 parser.set_defaults(cmpdays=False,
133 fields="nodename,ping,ssh,pcu,category,state,kernel,bootcd,rt",
134 dbname="findbad", # -070724-1",
140 parser.add_option("", "--fields", dest="dbname", help="")
141 parser.add_option("", "--dbname", dest="dbname", help="")
142 parser.add_option("", "--display", dest="display", action="store_true")
143 parser.add_option("", "--days", dest="cmpdays", action="store_true", help="")
144 parser.add_option("", "--ping", dest="cmpping", action="store_true", help="")
145 parser.add_option("", "--ssh", dest="cmpssh", action="store_true", help="")
146 parser.add_option("", "--category", dest="cmpcategory", action="store_true", help="")
147 parser.add_option("", "--kernel", dest="cmpkernel", action="store_true", help="")
148 parser.add_option("", "--state", dest="cmpstate", action="store_true", help="")
149 parser.add_option("", "--comon", dest="comon", help="")
150 config = parsermodule.parse_args(parser)