Massive commit of all changes, and added files for the Monitor-server package.
[monitor.git] / unified_model.py
index 58c223b..e0a6ffa 100755 (executable)
@@ -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():