+ widget = NodeWidget(template='monitorweb.templates.node_template')
+ return dict(now=time.ctime(), query=query, fc=filtercount, nodewidget=widget)
+
+ def nodeaction_handler(self, tg_exceptions=None):
+ """Handle any kind of error."""
+ print "NODEACTION_HANDLER------------------"
+
+ if 'pcuid' in request.params:
+ pcuid = request.params['pcuid']
+ else:
+ 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']).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(None, pcuid, **dict(exceptions=tg_exceptions))
+
+ def nodeaction(self, **data):
+ print "NODEACTION------------------"
+ for item in data.keys():
+ print "%s %s" % ( item, data[item] )
+
+ if 'hostname' in data:
+ hostname = data['hostname']
+ else:
+ flash("No hostname given in submitted data")
+ return
+
+ if 'submit' in data or 'type' in data:
+ try:
+ action = data['submit']
+ except:
+ action = data['type']
+ else:
+ flash("No submit action given in submitted data")
+ return
+
+ if action == "Reboot":
+ print "REBOOT: %s" % hostname
+ ret = reboot.reboot_str(str(hostname))
+ print ret
+ if ret: raise RuntimeError("Error using PCU: " + str(ret))
+ flash("Reboot appeared to work. Allow at most 5 minutes. Then run ExternalScan to check current status.")
+
+ elif action == "ExternalScan":
+ scanapi.externalprobe(str(hostname))
+ flash("External Scan Successful!")
+ elif action == "InternalScan":
+ scanapi.internalprobe(str(hostname))
+ flash("Internal Scan Successful!")
+ else:
+ # unknown action
+ raise RuntimeError("Unknown action given")
+ return
+
+ @expose(template="monitorweb.templates.simpleview")
+ def simpleview(self, **data):
+ return self.pre_view(**data)
+
+ @expose(template="monitorweb.templates.simpleview")
+ def pcuview(self, **data):
+ return self.pre_view(**data)
+
+ @expose(template="monitorweb.templates.detailview")
+ def detailview(self, **data):
+ return self.pre_view(**data)
+
+
+ def pre_view(self, **data):
+ 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']
+ 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']
+
+ if 'hostname' in data:
+ hostname = data['hostname']
+
+ if 'pcuid' in data:
+ try: pcuid = int(data['pcuid'])
+ except: pcuid = None
+
+ if 'since' in data:
+ try: since = int(since)
+ except: since = 20