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)
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:
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():
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":
sitequery=[]
pcuquery=[]
nodequery=[]
+ actions=[]
exceptions = None
for key in data:
exceptions = data['exceptions']
if loginbase:
+ actions = ActionRecord.query.filter_by(loginbase=loginbase
+ ).filter(ActionRecord.date_created >= datetime.now() - timedelta(7)
+ ).order_by(ActionRecord.date_created.desc())
+ actions = [ a for a in actions ]
sitequery = [HistorySiteRecord.by_loginbase(loginbase)]
pcus = {}
for plcnode in site_lb2hn[loginbase]:
- for node in FindbadNodeRecord.get_latest_by(hostname=plcnode['hostname']):
+ node = FindbadNodeRecord.get_latest_by(hostname=plcnode['hostname'])
# NOTE: reformat some fields.
prep_node_for_display(node)
nodequery += [node]
if pcuid and hostname is None:
print "pcuid: %s" % pcuid
- for pcu in FindbadPCURecord.get_latest_by(plc_pcuid=pcuid):
- # NOTE: count filter
- prep_pcu_for_display(pcu)
- pcuquery += [pcu]
+ pcu = FindbadPCURecord.get_latest_by(plc_pcuid=pcuid)
+ # NOTE: count filter
+ prep_pcu_for_display(pcu)
+ pcuquery += [pcu]
if 'site_id' in pcu.plc_pcu_stats:
sitequery = [HistorySiteRecord.by_loginbase(pcu.loginbase)]
if 'nodenames' in pcu.plc_pcu_stats:
for nodename in pcu.plc_pcu_stats['nodenames']:
print "query for %s" % nodename
- q = FindbadNodeRecord.get_latest_by(hostname=nodename)
- node = q.first()
+ node = FindbadNodeRecord.get_latest_by(hostname=nodename)
print "%s" % node.port_status
print "%s" % node.to_dict()
print "%s" % len(q.all())
nodequery += [node]
if hostname and pcuid is None:
- for node in FindbadNodeRecord.get_latest_by(hostname=hostname):
+ node = FindbadNodeRecord.get_latest_by(hostname=hostname)
# NOTE: reformat some fields.
prep_node_for_display(node)
sitequery = [node.site]
nodequery += [node]
if node.plc_pcuid: # not None
- pcu = FindbadPCURecord.get_latest_by(plc_pcuid=node.plc_pcuid).first()
+ pcu = FindbadPCURecord.get_latest_by(plc_pcuid=node.plc_pcuid)
prep_pcu_for_display(pcu)
pcuquery += [pcu]
- return dict(sitequery=sitequery, pcuquery=pcuquery, nodequery=nodequery, exceptions=exceptions)
+ return dict(sitequery=sitequery, pcuquery=pcuquery, nodequery=nodequery, actions=actions, exceptions=exceptions)
@expose(template="monitorweb.templates.pculist")
def pcu(self, filter='all'):
@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: