diff --git a/hbd b/hbd index fc67997..15b6952 100755 --- a/hbd +++ b/hbd @@ -423,12 +423,12 @@ def checkoverdue(): continue timeout = hbdclass.Host.hosts[h].interval + grace if conn.state == hbdclass.Connection.up and (now - conn.lastbeat) > timeout: - conn.newstate(hbdclass.Connection.overdue, now, grace) + conn.newstate(hbdclass.Connection.OVERDUE, now, grace) pmsg.append(conn.afam) if ( - conn.state == hbdclass.Connection.overdue and (now - conn.lastbeat) > DROPOVERDUE + conn.state == hbdclass.Connection.OVERDUE and (now - conn.lastbeat) > DROPOVERDUE ): - conn.newstate(hbdclass.Connection.unknown, conn.lastbeat) + conn.newstate(hbdclass.Connection.UNKNOWN, conn.lastbeat) if pmsg != []: if h in watchhosts: email("overdue", "%s overdue" % " and ".join(pmsg)) diff --git a/hbdclass.py b/hbdclass.py index 6a9501a..5d9d7cb 100644 --- a/hbdclass.py +++ b/hbdclass.py @@ -25,10 +25,10 @@ class Connection: # map of addrs to names htab = {} - unknown = "unknown" - up = "up" - down = "down" - overdue = "overdue" + UNKNOWN = "unknown" + UP = "up" + DOWN = "down" + OVERDUE = "overdue" def __init__(self, host, cid, addr, afam): self.host = host @@ -39,7 +39,7 @@ class Connection: self.lastbeat = time.time() self.statetime = self.lastbeat self.deltastatetime = "computed" - self.state = Connection.unknown + self.state = Connection.UNKNOWN if host: Connection.htab[addr] = self.host.name @@ -57,18 +57,18 @@ class Connection: d["addr"] = self.addr if self.rtts[-1]: d["rtt"] = "%0.1f" % self.rtts[-1] - elif self.state == Connection.unknown: + elif self.state == Connection.UNKNOWN: d["rtt"] = "" else: d["rtt"] = "?" d["lastbeat"] = self.lastbeat - if self.state == Connection.overdue: + if self.state == Connection.OVERDUE: d["state"] = "%s" % self.state else: d["state"] = self.state - if self.state == Connection.up: + if self.state == Connection.UP: d["rttstate"] = d["rtt"] - elif self.state == Connection.overdue: + elif self.state == Connection.OVERDUE: d["rttstate"] = "" else: d["rttstate"] = d["state"] @@ -77,7 +77,7 @@ class Connection: ) delta = now - self.statetime - if self.state == Connection.unknown: + if self.state == Connection.UNKNOWN: d["deltastatetime"] = "" elif delta > 86400: # d['deltastatetime'] = time.strftime("%d %H:%M:%S", time.gmtime(delta))