updated the model for actions, site history
[monitor.git] / web / MonitorWeb / monitorweb / controllers.py
index f4832ba..2112979 100644 (file)
@@ -132,6 +132,10 @@ def prep_node_for_display(node):
 
        if node.loginbase:
                node.site = HistorySiteRecord.by_loginbase(node.loginbase)
+               if node.site is None:
+                       # TODO: need a cleaner fix for this...
+                       node.site = HistorySiteRecord.by_loginbase("pl")
+                       
 
        node.history = HistoryNodeRecord.by_hostname(node.hostname)
 
@@ -168,13 +172,14 @@ class Root(controllers.RootController):
                import time
                fbquery = FindbadNodeRecord.get_all_latest()
                query = []
-               filtercount = {'DOWN' : 0, 'BOOT': 0, 'DEBUG' : 0, 'neverboot' : 0, 'pending' : 0, 'all' : 0}
+               filtercount = {'DOWN' : 0, 'BOOT': 0, 'DEBUG' : 0, 'neverboot' : 0, 'pending' : 0, 'all' : 0, None : 0}
                for node in fbquery:
                        # NOTE: reformat some fields.
                        prep_node_for_display(node)
 
                        # NOTE: count filters
                        if node.observed_status != 'DOWN':
+                               print node.hostname, node.observed_status
                                filtercount[node.observed_status] += 1
                        else:
                                if node.plc_node_stats and node.plc_node_stats['last_contact'] != None:
@@ -203,26 +208,32 @@ class Root(controllers.RootController):
        
        def nodeaction_handler(self, tg_exceptions=None):
                """Handle any kind of error."""
-               refurl = request.headers.get("Referer",link("pcu"))
-               print refurl
-
-               # TODO: do this more intelligently...
-               uri_fields = urllib.splitquery(refurl)
-               if uri_fields[1] is not None:
-                       val = query_to_dict(uri_fields[1])
-                       if 'pcuid' in val:
-                               pcuid = val['pcuid']
-                       elif 'hostname' in val:
-                               pcuid = FindbadNodeRecord.get_latest_by(hostname=val['hostname']).first().plc_pcuid
+
+               if 'pcuid' in request.params:
+                       pcuid = request.params['pcuid']
                else:
-                       pcuid=None
+                       refurl = request.headers.get("Referer",link("pcu"))
+                       print refurl
+
+                       # TODO: do this more intelligently...
+                       uri_fields = urllib.splitquery(refurl)
+                       if uri_fields[1] is not None:
+                               val = query_to_dict(uri_fields[1])
+                               if 'pcuid' in val:
+                                       pcuid = val['pcuid']
+                               elif 'hostname' in val:
+                                       pcuid = FindbadNodeRecord.get_latest_by(hostname=val['hostname']).first().plc_pcuid
+                               else:
+                                       pcuid=None
+                       else:
+                               pcuid=None
 
                cherry_trail = cherrypy._cputil.get_object_trail()
                for i in cherry_trail:
                        print "trail: ", i
 
                print pcuid
-               return self.pcuview(pcuid, **dict(exceptions=tg_exceptions))
+               return self.pcuview(None, pcuid, **dict(exceptions=tg_exceptions))
 
        def nodeaction(self, **data):
                for item in data.keys():
@@ -247,7 +258,7 @@ class Root(controllers.RootController):
                        print "REBOOT: %s" % hostname
                        ret = reboot.reboot_str(str(hostname))
                        print ret
-                       if ret: raise RuntimeError("Error using PCU: " + ret)
+                       if ret: raise RuntimeError("Error using PCU: " + str(ret))
                        flash("Reboot appeared to work.  All at most 5 minutes.  Run ExternalScan to check current status.")
 
                elif action == "ExternalScan":
@@ -378,7 +389,7 @@ class Root(controllers.RootController):
 
        @expose(template="monitorweb.templates.sitelist")
        def site(self, filter='all'):
-               filtercount = {'good' : 0, 'down': 0, 'new' : 0, 'pending' : 0, 'all' : 0}
+               filtercount = {'good' : 0, 'down': 0, 'online':0, 'offline' : 0, 'new' : 0, 'pending' : 0, 'all' : 0}
                fbquery = HistorySiteRecord.query.all()
                query = []
                for site in fbquery: