add functions for pcuview, nodeview, & siteview
Stephen Soltesz [Thu, 4 Dec 2008 23:29:42 +0000 (23:29 +0000)]
monitor/database/info/findbad.py
web/MonitorWeb/monitorweb/controllers.py
web/MonitorWeb/monitorweb/static/css/style.css

index 13132d1..566c2ae 100644 (file)
@@ -30,8 +30,11 @@ class FindbadNodeRecord(Entity):
        @classmethod
        def get_latest_by(cls, **kwargs):
                fbsync = FindbadNodeRecordSync.get_by(hostname="global")
-               kwargs['round'] = fbsync.round
-               return cls.query.filter_by(**kwargs)
+               if fbsync:
+                       kwargs['round'] = fbsync.round
+                       return cls.query.filter_by(**kwargs)
+               else:
+                       return []
 
        @classmethod
        def get_latest_n_by(cls, n=3, **kwargs):
index be94316..95d9740 100644 (file)
@@ -12,6 +12,7 @@ from monitor.database.dborm import zab_metadata as metadata
 from pcucontrol import reboot
 from monitor.wrapper.plccache import plcdb_id2lb as site_id2lb
 from monitor.wrapper.plccache import plcdb_hn2lb as site_hn2lb
+from monitor.wrapper.plccache import plcdb_lb2hn as site_lb2hn
 
 def format_ports(pcu):
        retval = []
@@ -41,6 +42,40 @@ def format_pcu_shortstatus(pcu):
 
        return status
 
+def prep_pcu_for_display(pcu):
+               
+       try:
+               pcu.loginbase = site_id2lb[pcu.plc_pcu_stats['site_id']]
+       except:
+               pcu.loginbase = "unknown"
+
+       pcu.ports = format_ports(pcu)
+       pcu.status = format_pcu_shortstatus(pcu)
+
+def prep_node_for_display(node):
+       if node.plc_pcuid:
+               pcu = FindbadPCURecord.get_latest_by(plc_pcuid=node.plc_pcuid).first()
+               if pcu:
+                       node.pcu_status = pcu.reboot_trial_status
+               else:
+                       node.pcu_status = "nodata"
+               node.pcu_short_status = format_pcu_shortstatus(pcu)
+
+       else:
+               node.pcu_status = "nopcu"
+               node.pcu_short_status = "none"
+
+       if node.kernel_version:
+               node.kernel = node.kernel_version.split()[2]
+       else:
+               node.kernel = ""
+
+       try:
+               node.loginbase = site_id2lb[node.plc_node_stats['site_id']]
+       except:
+               node.loginbase = "unknown"
+       
+
 class Root(controllers.RootController):
        @expose(template="monitorweb.templates.welcome")
        def index(self):
@@ -49,6 +84,17 @@ class Root(controllers.RootController):
                flash("Your application is now running")
                return dict(now=time.ctime())
 
+       @expose(template="monitorweb.templates.nodeview")
+       def nodeview(self, hostname=None):
+               nodequery=[]
+               if hostname:
+                       for node in FindbadNodeRecord.get_latest_by(hostname=hostname):
+                               # NOTE: reformat some fields.
+                               prep_node_for_display(node)
+                               nodequery += [node]
+
+               return dict(nodequery=nodequery)
+
        @expose(template="monitorweb.templates.nodelist")
        def node(self, filter='BOOT'):
                import time
@@ -57,28 +103,7 @@ class Root(controllers.RootController):
                filtercount = {'DOWN' : 0, 'BOOT': 0, 'DEBUG' : 0, 'neverboot' : 0, 'pending' : 0, 'all' : 0}
                for node in fbquery:
                        # NOTE: reformat some fields.
-                       if node.plc_pcuid:
-                               pcu = FindbadPCURecord.get_latest_by(plc_pcuid=node.plc_pcuid).first()
-                               if pcu:
-                                       node.pcu_status = pcu.reboot_trial_status
-                               else:
-                                       node.pcu_status = "nodata"
-                               node.pcu_short_status = format_pcu_shortstatus(pcu)
-
-                       else:
-                               node.pcu_status = "nopcu"
-                               node.pcu_short_status = "none"
-
-                       if node.kernel_version:
-                               node.kernel = node.kernel_version.split()[2]
-                       else:
-                               node.kernel = ""
-
-                       try:
-                               node.loginbase = site_id2lb[node.plc_node_stats['site_id']]
-                       except:
-                               node.loginbase = "unknown"
-
+                       prep_node_for_display(node)
 
                        # NOTE: count filters
                        if node.observed_status != 'DOWN':
@@ -107,6 +132,17 @@ class Root(controllers.RootController):
                                
                return dict(now=time.ctime(), query=query, fc=filtercount)
 
+       @expose(template="monitorweb.templates.pcuview")
+       def pcuview(self, pcuid=None):
+               pcuquery=[]
+               if pcuid:
+                       for pcu in FindbadPCURecord.get_latest_by(plc_pcuid=pcuid):
+                               # NOTE: count filter
+                               prep_pcu_for_display(pcu)
+                               pcuquery += [pcu]
+
+               return dict(pcuquery=pcuquery)
+
        @expose(template="monitorweb.templates.pculist")
        def pcu(self, filter='all'):
                import time
@@ -116,20 +152,14 @@ class Root(controllers.RootController):
                for node in fbquery:
 
                        # NOTE: count filter
-                       if node.reboot_trial_status == str(0):
+                       if pcu.reboot_trial_status == str(0):
                                filtercount['ok'] += 1
-                       elif node.reboot_trial_status == 'NetDown' or node.reboot_trial_status == 'Not_Run':
-                               filtercount[node.reboot_trial_status] += 1
+                       elif pcu.reboot_trial_status == 'NetDown' or pcu.reboot_trial_status == 'Not_Run':
+                               filtercount[pcu.reboot_trial_status] += 1
                        else:
                                filtercount['pending'] += 1
-                               
-                       try:
-                               node.loginbase = site_id2lb[node.plc_pcu_stats['site_id']]
-                       except:
-                               node.loginbase = "unknown"
 
-                       node.ports = format_ports(node)
-                       node.status = format_pcu_shortstatus(node)
+                       prep_pcu_for_display(node)
 
                        # NOTE: apply filter
                        if filter == "all":
@@ -148,6 +178,18 @@ class Root(controllers.RootController):
                                
                return dict(query=query, fc=filtercount)
 
+       @expose(template="monitorweb.templates.siteview")
+       def siteview(self, loginbase='pl'):
+               # get site query
+               sitequery = [HistorySiteRecord.by_loginbase(loginbase)]
+               nodequery = []
+               for plcnode in site_lb2hn[loginbase]:
+                       for node in FindbadNodeRecord.get_latest_by(hostname=plcnode['hostname']):
+                               # NOTE: reformat some fields.
+                               prep_node_for_display(node)
+                               nodequery += [node]
+               return dict(sitequery=sitequery, nodequery=nodequery, fc={})
+
        @expose(template="monitorweb.templates.sitelist")
        def site(self, filter='all'):
                filtercount = {'good' : 0, 'down': 0, 'new' : 0, 'pending' : 0, 'all' : 0}
index 60c902e..5a6b72c 100644 (file)
@@ -50,6 +50,10 @@ a.link, a, a.active {
 #site-good { background-color : darkseagreen; }\r
 #site-down { background-color: indianred; }\r
 \r
+#node-BOOT { background-color: darkseagreen; }\r
+#node-DOWN { background-color: indianred; }\r
+#node-DEBUG { background-color: gold; }\r
+\r
 #severity-0     {   background-color: #AADDAA;  }\r
 #severity-1     {   background-color: #CCE2CC;  }\r
 #severity-2     {   background-color: #EFEFCC;  }\r