diff --git a/hbd b/hbd index 532f7a2..dfe1fe1 100755 --- a/hbd +++ b/hbd @@ -34,6 +34,7 @@ SEND_PUSHOVER=True DEBUG = 0 MAXRECV = 32767 +MAXRTTS = 10 LOGFILE = "/home/andreas/public_html/messages/andreas" PICKFILE = "/var/tmp/hbd.pick" AEMAIL = ["andreas@wrede.ca"] @@ -143,13 +144,12 @@ def oldmtodict(msg): class Connection: - def __init__(self, name, cid, addr, port): + def __init__(self, name, cid, addr): self.name = name self.cid = cid self.addr = addr - self.port = port + self.rtts = [0] - class Host: up = "up" @@ -271,9 +271,11 @@ class Host: self.cver = 0 try: - a=host.connections + a=self.connections + a.append([]) except: - host.connections=[] + self.connections={} + self.connections={} def getstate(self): @@ -284,7 +286,12 @@ class Host: if self.state in ["down", "overdue"]: state = "%s" % self.state elif self.state in ["up", "UP"]: - state = "%0.1f" % self.latency + state = "" + for x in self.connections.keys(): + try: + state += " %5.1f" % self.connections[x].rtts[-1] + except: + state += " %5s" % self.connections[x].rtts[-1] else: state = "%s" % self.state return state @@ -486,15 +493,15 @@ def log(host, m, service=None): def dnsupdatethread(): while True: name, addr = dnsQ.get() - m = "%s changed address to %s" % (name, addr) + m = "changed address to %s" % (addr) err = nsupdate(name, addr) if err: - m += ", DNS failed: %s" % err - email("error: nsupdate failed", m) + m += ", DNS update failed: %s" % err + email("error: nsupdate failed", "%s: %s" % (name, m)) else: m += ", DNS updated." dnsQ.task_done() - log(m) + log(name, m) # # @@ -536,6 +543,10 @@ def readsock(sock): message = msg.get('msg', None) boot = msg.get('boot', 0) host.latency = now - msg.get('time', 0) + rtt = msg.get('rtt',"up") + conn.rtts.append(rtt) + if len(conn.rtts) > MAXRTTS: + del conn.rtts[0] if boot: log(name, "booted") @@ -689,8 +700,9 @@ class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler): (h, hosts[h].dispstate(), hosts[h].dispstats(), hosts[h].addr4, hosts[h].addr6, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hosts[h].statetime)), hosts[h].cver)) res.append("") + le = max(40 - len(hosts), 3) res.append("