From 09b59c841e16304b3f0826e6866e212bad922840 Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Mon, 17 Aug 2009 21:49:31 +0000 Subject: [PATCH] added advanced query added simple and detailed view rather than single, 'pcuview' simplified nodelist clarified some labels added error page for quickjumps without a target added site:* and node:* queries for quickjump: now you can see all sites that match a pattern: site:mlab* or node:*clara* --- web/MonitorWeb/monitorweb/controllers.py | 232 ++++++++++++++---- .../monitorweb/static/css/style.css | 15 +- .../monitorweb/templates/detailview.kid | 47 ++-- .../monitorweb/templates/node_template.kid | 2 +- .../monitorweb/templates/nodefast.kid | 75 ++++++ .../monitorweb/templates/nodelist.kid | 2 +- .../monitorweb/templates/nodescanhistory.kid | 2 +- .../monitorweb/templates/pculist.kid | 10 +- .../monitorweb/templates/pcuview.kid | 4 +- web/MonitorWeb/monitorweb/templates/query.kid | 63 +++++ .../monitorweb/templates/simpleview.kid | 19 +- .../monitorweb/templates/sitelist.kid | 4 +- .../monitorweb/templates/sitemenu.kid | 5 +- 13 files changed, 383 insertions(+), 97 deletions(-) create mode 100644 web/MonitorWeb/monitorweb/templates/nodefast.kid create mode 100644 web/MonitorWeb/monitorweb/templates/query.kid diff --git a/web/MonitorWeb/monitorweb/controllers.py b/web/MonitorWeb/monitorweb/controllers.py index 1ce95cc..2821b76 100644 --- a/web/MonitorWeb/monitorweb/controllers.py +++ b/web/MonitorWeb/monitorweb/controllers.py @@ -21,6 +21,67 @@ from monitor.wrapper.plccache import plcdb_hn2lb as site_hn2lb from monitorweb.templates.links import * +class ObjectQueryFields(widgets.WidgetsList): + """The WidgetsList defines the fields of the form.""" + pass + + + +class NodeQueryFields(widgets.WidgetsList): + """The WidgetsList defines the fields of the form.""" + + object = widgets.RadioButtonList(label="Query Type", options=[('nodes', 'All Nodes'), + ('nodehistory', 'Single Node History'), + #('sites', 'All Sites'), + #('sitehistory', 'Single Site History'), + ], default="nodes") + nodehistory_hostname = widgets.TextField(label="Hostname Node History", attrs={'size':30}) + + hostname = widgets.CheckBox(label="Hostname") + firewall = widgets.CheckBox(label="Firewall?") + dns_status = widgets.CheckBox(label="DNS Status") + external_dns_status = widgets.CheckBox(label="Hostname Resolves?") + kernel_version = widgets.CheckBox(label="Kernel") + observed_status = widgets.CheckBox(label="Observed Status") + port_status = widgets.CheckBox(label="Port Status") + rpms = widgets.CheckBox(label="RPM") + rpmvalue = widgets.TextField(label="RPM Pattern") + +class QueryForm(widgets.TableForm): + template = """ +
+
+ + + + + + + + +
+ + + + +
  +
+ + """ + +def getNodeQueryForm(): + return QueryForm(fields=NodeQueryFields(), action="query") # make it easier group objects without invoking the elixir auto-write feature. class aggregate: pass @@ -110,6 +171,18 @@ def prep_pcu_for_display(pcu): class NodeWidget(widgets.Widget): pass +def prep_nodehist(node): + agg = aggregate() + agg.node = node + agg.loginbase = "unknown" + try: + agg.loginbase = PlcSite.query.get(node.plc_siteid).plc_site_stats['login_base'] + except: + agg.loginbase = "exception" + + + return agg + def prep_node_for_display(node, pcuhash=None, preppcu=True, asofdate=None): agg = aggregate() agg.node = node @@ -214,33 +287,68 @@ class Root(controllers.RootController, MonitorXmlrpcServer): agg = prep_node_for_display(fb) rquery.append(agg) - #fbquery = FindbadNodeRecord.get_all_latest() - #fbpcus = FindbadPCURecord.get_all_latest() - #def fbtohash(fbpculist): - # h = {} - # for p in fbpculist: - # h[p.plc_pcuid] = p -# -# pcuhash = fbtohash(fbpcus) - -# query = [] -# for node in fbquery: -# # NOTE: reformat some fields. -# agg = prep_node_for_display(node, pcuhash) -# if not agg.history: -# continue -# -# if filter: -# if agg.history.status == filter: -# query.append(agg) -# else: -# query.append(agg) - widget = NodeWidget(template='monitorweb.templates.node_template') return dict(now=time.ctime(), query=rquery, nodewidget=widget) + @expose(template="monitorweb.templates.query", allow_json=True) + def query(self, **data): + query = [] + + for k in data: + print k, data[k] + + fbquery = None + + if 'object' in data and data['object'] == "nodes": + fbquery = FindbadNodeRecord.get_all_latest() + elif 'object' in data and data['object'] == "nodehistory": + hostname = data['nodehistory_hostname'] + data['date_checked'] = 'date_checked' + fbrecord = FindbadNodeRecord.get_by(hostname=hostname) + fbquery = fbrecord.versions[-500:] + + if fbquery: + for node in fbquery: + # NOTE: reformat some fields. + if type(node) is not type(FindbadNodeRecord): + agg = node.__dict__.copy() + else: + agg = node.to_dict() + agg.update(agg['plc_node_stats']) + if 'rpmvalue' in data and 'rpms' in data: + if agg['rpms']: + rpm_list = agg['rpms'].split() + rpm_list = filter(lambda x: data['rpmvalue'] in x, rpm_list) + agg['rpms'] = " ".join(rpm_list) + + query.append(agg) + + fields=data.copy() + + try: + del fields['object'] + del fields['rpmvalue'] + del fields['nodehistory_hostname'] + except: pass + return dict(now=time.ctime(), query=query, fields=fields, data=data, queryform=getNodeQueryForm()) + + @expose(template="monitorweb.templates.nodefast", allow_json=True) + def node(self, filter=None): + nhquery = HistoryNodeRecord.query.all() + query = [] + for nh in nhquery: + if filter: + if nh.status == filter: + agg = prep_nodehist(nh) + query.append(agg) + else: + agg = prep_nodehist(nh) + query.append(agg) + + return dict(now=time.ctime(), query=query) + @expose(template="monitorweb.templates.nodelist") - def node(self, filter='boot'): + def nodeslow(self, filter='boot'): print "NODE------------------" print "befor-len: ", len( [ i for i in session] ) session.flush(); session.clear() @@ -365,23 +473,35 @@ class Root(controllers.RootController, MonitorXmlrpcServer): session.flush(); session.clear() loginbase=None + loginbase_list=[] hostname=None pcuid=None since=20 + # if objtype is not None, then treat 'hostname' or 'loginbase' as a search pattern + objtype=None exceptions = None sitequery=[] nodequery=[] pcuquery=[] actions=[] + actions_list=[] for key in data: print key, data[key] if 'query' in data: obj = data['query'] - if len(obj.split(".")) > 1: hostname = obj - else: loginbase=obj + fields = obj.split(":") + if len(fields) > 1: + objtype = fields[0] + obj = fields[1].replace("*", "%") + print "obj: %s"% obj + + if len(obj.split(".")) > 1 or objtype == "node": + hostname = obj + else: + loginbase = obj if 'loginbase' in data: loginbase = data['loginbase'] @@ -400,32 +520,50 @@ class Root(controllers.RootController, MonitorXmlrpcServer): if pcuid: print "pcuid: %s" % pcuid pcu = FindbadPCURecord.get_latest_by(plc_pcuid=pcuid) - loginbase = PlcSite.query.get(pcu.plc_pcu_stats['site_id']).plc_site_stats['login_base'] + loginbase_list += [ PlcSite.query.get(pcu.plc_pcu_stats['site_id']).plc_site_stats['login_base'] ] if hostname: - node = FindbadNodeRecord.get_latest_by(hostname=hostname) - loginbase = PlcSite.query.get(node.plc_node_stats['site_id']).plc_site_stats['login_base'] - - if loginbase: - actions = ActionRecord.query.filter_by(loginbase=loginbase - ).filter(ActionRecord.date_created >= datetime.now() - timedelta(since) - ).order_by(ActionRecord.date_created.desc()) - actions = [ a for a in actions ] - sitequery = [HistorySiteRecord.by_loginbase(loginbase)] - # NOTE: because a single pcu may be assigned to multiple hosts, - # track unique pcus by their plc_pcuid, then turn dict into list - pcus = {} - for node in FindbadNodeRecord.query.filter_by(loginbase=loginbase): - # NOTE: reformat some fields. - agg = prep_node_for_display(node) - nodequery += [agg] - if agg.pcu: - pcus[agg.pcu.pcu.plc_pcuid] = agg.pcu + if not objtype: + nodes = [ FindbadNodeRecord.get_latest_by(hostname=hostname) ] + else: + nodes = FindbadNodeRecord.query.filter(FindbadNodeRecord.hostname.like(hostname)) - for pcuid_key in pcus: - pcuquery += [pcus[pcuid_key]] + for node in nodes: + lb = PlcSite.query.get(node.plc_node_stats['site_id']).plc_site_stats['login_base'] + if lb not in loginbase_list: + loginbase_list += [ lb ] - return dict(sitequery=sitequery, pcuquery=pcuquery, nodequery=nodequery, actions=actions, since=since, exceptions=exceptions) + if loginbase: + if not objtype: + loginbase_list = [ loginbase ] + else: + loginbase_list = HistorySiteRecord.query.filter(HistorySiteRecord.loginbase.like(loginbase)) + loginbase_list = [ l.loginbase for l in loginbase_list ] + + + if loginbase_list: + for loginbase in loginbase_list: + actions = ActionRecord.query.filter_by(loginbase=loginbase + ).filter(ActionRecord.date_created >= datetime.now() - timedelta(since) + ).order_by(ActionRecord.date_created.desc()) + actions_list += [ a for a in actions ] + site = HistorySiteRecord.by_loginbase(loginbase) + if site: + sitequery.append(site) + # NOTE: because a single pcu may be assigned to multiple hosts, + # track unique pcus by their plc_pcuid, then turn dict into list + pcus = {} + for node in FindbadNodeRecord.query.filter_by(loginbase=loginbase): + # NOTE: reformat some fields. + agg = prep_node_for_display(node) + nodequery += [agg] + if agg.pcu: + pcus[agg.pcu.pcu.plc_pcuid] = agg.pcu + + for pcuid_key in pcus: + pcuquery += [pcus[pcuid_key]] + + return dict(sitequery=sitequery, pcuquery=pcuquery, nodequery=nodequery, actions=actions_list, since=since, exceptions=exceptions) # TODO: add form validation diff --git a/web/MonitorWeb/monitorweb/static/css/style.css b/web/MonitorWeb/monitorweb/static/css/style.css index ac85b33..71d6cca 100644 --- a/web/MonitorWeb/monitorweb/static/css/style.css +++ b/web/MonitorWeb/monitorweb/static/css/style.css @@ -115,6 +115,9 @@ a.right { float: right; } #node-good { background-color : darkseagreen; } #node-offline { background-color: red; } #node-down { background-color: indianred; } +#node-failboot { background-color: gold; } +#node-safeboot { background-color: lightyellow; } +#node-disabled { background-color: grey; } #pcu-online { background-color : lightgreen; } #pcu-good { background-color : darkseagreen; } @@ -145,7 +148,7 @@ a.right { float: right; } color: black; font-size: 127%; background-color: white; - width: 757px; + /*width: 757px;*/ margin: 0 auto 0 auto; border-left: 1px solid #aaa; border-right: 1px solid #aaa; @@ -158,7 +161,7 @@ a.right { float: right; } margin: 0.5em; padding: 1em; float: right; - width: 200px; + /*width: 200px;*/ font-size: 88%; } @@ -209,7 +212,7 @@ h2 { padding: 10px; font-size: 80%; text-align: center; - width: 765px; + /*width: 765px;*/ margin: 0 auto 1em auto; } @@ -229,7 +232,7 @@ span.code { padding: 15px 10px 15px 55px; background: #cec URL('../images/ok.png') left center no-repeat; border: 1px solid #9c9; - width: 450px; + /*width: 450px;*/ font-size: 120%; font-weight: bolder; } @@ -237,14 +240,14 @@ span.code { .notice { margin: 0.5em auto 0.5em auto; padding: 15px 10px 15px 55px; - width: 450px; + /*width: 450px;*/ background: #eef URL('../images/info.png') left center no-repeat; border: 1px solid #cce; } .error { margin: 0.5em auto 0.5em auto; padding: 15px 10px 15px 55px; - width: 450px; + /*width: 450px;*/ background: #e30 URL('../images/widgets.png') left center no-repeat; border: 1px solid #c00; } diff --git a/web/MonitorWeb/monitorweb/templates/detailview.kid b/web/MonitorWeb/monitorweb/templates/detailview.kid index 5881d98..e86bbb1 100644 --- a/web/MonitorWeb/monitorweb/templates/detailview.kid +++ b/web/MonitorWeb/monitorweb/templates/detailview.kid @@ -145,16 +145,17 @@ from links import * History (scan) Status Since Hostname - DNS + Resolves? SSH last_contact (cached) Last Checked Port Status - Firewall + Blocked Ports? - + + status (scan) @@ -171,31 +172,23 @@ from links import * id="port${state}" py:content="'%s, ' % port">80 - - - - - - - - - - - - + + + Kernel: + + + + + DNS Status: +
 
+ + + + Traceroute: +
 
+ +
diff --git a/web/MonitorWeb/monitorweb/templates/node_template.kid b/web/MonitorWeb/monitorweb/templates/node_template.kid index 3e1583a..c50a745 100644 --- a/web/MonitorWeb/monitorweb/templates/node_template.kid +++ b/web/MonitorWeb/monitorweb/templates/node_template.kid @@ -18,7 +18,7 @@ from links import * last_contact - node_id + node_id your.host.org diff --git a/web/MonitorWeb/monitorweb/templates/nodefast.kid b/web/MonitorWeb/monitorweb/templates/nodefast.kid new file mode 100644 index 0000000..97072d2 --- /dev/null +++ b/web/MonitorWeb/monitorweb/templates/nodefast.kid @@ -0,0 +1,75 @@ + + + + +
+ + + +
+ | +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + reset visible size +
+
IDSiteHostnameStatusLast ChangedFirewall
node_id ${agg.loginbase} your.host.orgboot
+ +
+ + diff --git a/web/MonitorWeb/monitorweb/templates/nodelist.kid b/web/MonitorWeb/monitorweb/templates/nodelist.kid index 4f4425a..e32b92d 100644 --- a/web/MonitorWeb/monitorweb/templates/nodelist.kid +++ b/web/MonitorWeb/monitorweb/templates/nodelist.kid @@ -36,7 +36,7 @@ from links import *