X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=blobdiff_plain;f=monitor%2Fdatabase%2Finfo%2Ffindbad.py;h=615e03fe7c87074fac9185b9f079226a25a4d6e5;hp=0cfb965cf74c7c9eccb006988aeac1e4c85b142c;hb=57fc3f2c580971f7a31c708764557d6273b83216;hpb=ab835ed0e99bc4c57728c8cfa61856d15dfc34f5 diff --git a/monitor/database/info/findbad.py b/monitor/database/info/findbad.py index 0cfb965..615e03f 100644 --- a/monitor/database/info/findbad.py +++ b/monitor/database/info/findbad.py @@ -5,6 +5,7 @@ from datetime import datetime,timedelta import elixir import traceback from elixir.ext.versioned import * +from pcucontrol import reboot from monitor.database.dborm import mon_metadata, mon_session __metadata__ = mon_metadata @@ -77,6 +78,68 @@ class FindbadPCURecord(Entity): def get_latest_by(cls, **kwargs): return cls.query.filter_by(**kwargs).first() + def pcu_name(self): + if self.plc_pcu_stats['hostname'] is not None and self.plc_pcu_stats['hostname'] is not "": + return self.plc_pcu_stats['hostname'] + elif self.plc_pcu_stats['ip'] is not None and self.plc_pcu_stats['ip'] is not "": + return self.plc_pcu_stats['ip'] + else: + return None + + def format_ports(self): + retval = [] + filtered_length=0 + + supported_ports=reboot.model_to_object(self.plc_pcu_stats['model']).supported_ports + data = self.port_status.copy() + + if data and len(data.keys()) > 0 : + for port in supported_ports: + try: + state = data[str(port)] + except: + state = "unknown" + + if state == "filtered": + filtered_length += 1 + + retval.append( (port, state) ) + + if retval == []: + retval = [( "Closed/Filtered", "" )] + + if filtered_length == len(supported_ports): + retval = [( "All Filtered", "" )] + + return retval + + def format_pcu_shortstatus(self): + status = "error" + if self.reboot_trial_status: + if self.reboot_trial_status == str(0): + status = "Ok" + elif self.reboot_trial_status == "NetDown" or self.reboot_trial_status == "Not_Run": + status = self.reboot_trial_status + else: + status = "error" + + return status + + def test_is_ok(self): + if self.reboot_trial_status == str(0): + return True + else: + return False + + def pcu_errors(self): + message = "\n" + message += "\tModel: %s\n" % self.plc_pcu_stats['model'] + message += "\tMissing Fields: %s\n" % ( self.entry_complete == "" and "None missing" or self.entry_complete ) + message += "\tDNS Status: %s\n" % self.dns_status + message += "\tPort Status: %s\n" % self.format_ports() + message += "\tTest Results: %s\n" % self.format_pcu_shortstatus() + return message + # ACCOUNTING date_checked = Field(DateTime) round = Field(Int,default=0)