X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unified_model.py;h=e0a6ffaff078bb8d72c1786206d5ff9b5ac0a4f3;hb=d0652340b89d51c6115edb13d5c7c72b34dea66f;hp=58c223be8e5172829600e8bae81e1b33692424fc;hpb=9a5afb968bf6ee5c9b03470c957b98906d3b78a9;p=monitor.git diff --git a/unified_model.py b/unified_model.py index 58c223b..e0a6ffa 100755 --- a/unified_model.py +++ b/unified_model.py @@ -449,12 +449,11 @@ class Record(object): def getDaysDown(cls, diag_record): daysdown = -1 if diag_record['comonstats']['uptime'] != "null": - #print "uptime %s" % (int(float(diag_record['comonstats']['uptime'])) // (60*60*24)) daysdown = - int(float(diag_record['comonstats']['uptime'])) // (60*60*24) - elif diag_record['comonstats']['sshstatus'] != "null": - daysdown = int(diag_record['comonstats']['sshstatus']) // (60*60*24) - elif diag_record['comonstats']['lastcotop'] != "null": - daysdown = int(diag_record['comonstats']['lastcotop']) // (60*60*24) + #elif diag_record['comonstats']['sshstatus'] != "null": + # daysdown = int(diag_record['comonstats']['sshstatus']) // (60*60*24) + #elif diag_record['comonstats']['lastcotop'] != "null": + # daysdown = int(diag_record['comonstats']['lastcotop']) // (60*60*24) else: now = time.time() last_contact = diag_record['plcnode']['last_contact'] @@ -468,15 +467,41 @@ class Record(object): getDaysDown = classmethod(getDaysDown) def getStrDaysDown(cls, diag_record): - daysdown = cls.getDaysDown(diag_record) - if daysdown > 0: - return "%d days down"%daysdown - elif daysdown == -1: - return "Unknown number of days" + daysdown = "unknown" + last_contact = diag_record['plcnode']['last_contact'] + date_created = diag_record['plcnode']['date_created'] + + if diag_record['comonstats']['uptime'] != "null" and \ + diag_record['comonstats']['uptime'] != "-1": + daysdown = int(float(diag_record['comonstats']['uptime'])) // (60*60*24) + daysdown = "%d days up" % daysdown + + elif last_contact is None: + if date_created is not None: + now = time.time() + diff = now - date_created + daysdown = diff // (60*60*24) + daysdown = "Never contacted PLC, created %s days ago" % daysdown + else: + daysdown = "Never contacted PLC" else: - return "%d days up"% -daysdown + now = time.time() + diff = now - last_contact + daysdown = diff // (60*60*24) + daysdown = "%s days down" % daysdown + return daysdown getStrDaysDown = classmethod(getStrDaysDown) + #def getStrDaysDown(cls, diag_record): + # daysdown = cls.getDaysDown(diag_record) + # if daysdown > 0: + # return "%d days down"%daysdown + # elif daysdown == -1: + # return "Never online" + # else: + # return "%d days up"% -daysdown + #getStrDaysDown = classmethod(getStrDaysDown) + def takeAction(self): pp = PersistSitePenalty(self.hostname, 0, db='persistpenalty_hostnames') if 'improvement' in self.data['stage'] or self.improved():