start html cleanup

This commit is contained in:
2016-04-24 17:02:15 +02:00
parent c192a6ea36
commit 4848e079a1
2 changed files with 20 additions and 9 deletions
+1 -2
View File
@@ -369,7 +369,6 @@ except:
for o,a in optlist: for o,a in optlist:
if o == '-b': if o == '-b':
msgboot['boot']=1 msgboot['boot']=1
msgonly=True
elif o == '-c': elif o == '-c':
configfile=a configfile=a
cmdargs += [o, a] cmdargs += [o, a]
@@ -486,7 +485,7 @@ if msgonly:
# #
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON) syslog.openlog('hbc', syslog.LOG_PID, syslog.LOG_DAEMON)
if fdaemon: if fdaemon:
pidfile = daemon.pidfile.TimeoutPIDLockFile(PIDFILE, acquire_timeout=-1) pidfile = daemon.pidfile.TimeoutPIDLockFile(PIDFILE, acquire_timeout=-1)
+19 -7
View File
@@ -275,7 +275,6 @@ class Host:
a.append([]) a.append([])
except: except:
self.connections={} self.connections={}
self.connections={}
def getstate(self): def getstate(self):
@@ -289,15 +288,16 @@ class Host:
state = "" state = ""
for x in self.connections.keys(): for x in self.connections.keys():
try: try:
state += " %5.1f" % self.connections[x].rtts[-1] state += " %5.1f" % (self.connections[x].rtts[-1])
except: except:
state += " %5s" % self.connections[x].rtts[-1] state += " %5s" % (self.connections[x].rtts[-1])
else: else:
state = "%s" % self.state state = "%s" % self.state
return state return state
def dispstats(self): def dispstats(self):
return '<td align="right">N/A</td><td></td<td></td>'
if self.doesack != -1: if self.doesack != -1:
if self.upcount > 0: if self.upcount > 0:
# return "(%0.1f%%) %s %s %s " % ((self.doesack * 100.0) / self.upcount, self.doesack, self.upcount, self.hdwcounts) # return "(%0.1f%%) %s %s %s " % ((self.doesack * 100.0) / self.upcount, self.doesack, self.upcount, self.hdwcounts)
@@ -317,6 +317,19 @@ class Host:
return '<td align="right">N/A</td><td></td<td></td>>' return '<td align="right">N/A</td><td></td<td></td>>'
def htmldisp(self, header=False):
if header:
return "<tr><th>Host</th><th>State</th><th>Hr</th><th>Dy</th><th>Wk</th><th>IP4 Addr</th><th>IP6 Addr</th><th>Last change</th><th>Ver</th></tr>\n"
else:
ipv4addr = self.addr4 if self.addr4 else ""
ipv6addr = self.addr6 if self.addr6 else ""
lastts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.statetime))
return "<tr><td>%-24s</td><td>%-7s</td>%s<td>%-16s</td><td>%-16s</td><td>%-17s</td><td>%s</td></tr>\n" % \
(self.name, self.dispstate(), self.dispstats(), ipv4addr, ipv6addr, lastts, self.cver)
# set new state, return number of secs in previous state # set new state, return number of secs in previous state
def newstate(self, state, when=0): def newstate(self, state, when=0):
self.state = state self.state = state
@@ -584,7 +597,7 @@ def readsock(sock):
log(name, "shutdown") log(name, "shutdown")
if name in watchhosts: if name in watchhosts:
email("shutdown", "%s shutdown" % name) email("shutdown", "%s shutdown" % name)
pushover(m) pushover("%s hbc shutdown" % name)
try: try:
host.newstate(Host.down) host.newstate(Host.down)
except: except:
@@ -692,12 +705,11 @@ class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
res.append("<H2>Heartbeat status %s</h2><h4> %s (%s)</H4>" % (VER, time.strftime("%H:%M:%S", time.localtime(now)), os.environ.get('TZ', 'CET-1CDT'))) res.append("<H2>Heartbeat status %s</h2><h4> %s (%s)</H4>" % (VER, time.strftime("%H:%M:%S", time.localtime(now)), os.environ.get('TZ', 'CET-1CDT')))
res.append("<table>") res.append("<table>")
res.append("<tr><th>Host</th><th>State</th><th>Hr</th><th>Dy</th><th>Wk</th><th>IP4 Addr</th><th>IP6 Addr</th><th>Last change</th><th>Ver</th></tr>\n")
hosts_sorted = hosts.keys() hosts_sorted = hosts.keys()
hosts_sorted.sort() hosts_sorted.sort()
res.append(hosts[hosts_sorted[0]].htmldisp(True))
for h in hosts_sorted: for h in hosts_sorted:
res.append("<tr><td>%-24s</td><td>%-7s</td>%s<td>%-16s</td><td>%-16s</td><td>%-17s</td><td>%s</td></tr>\n" % \ res.append(hosts[h].htmldisp())
(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("</table>") res.append("</table>")
le = max(40 - len(hosts), 3) le = max(40 - len(hosts), 3)