key on hostname not IP address
sort display beginning of signal processing
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# $Id: hbd,v 1.11 2006/04/28 12:53:08 andreas Exp $
|
||||
# $Id: hbd,v 1.12 2006/11/07 19:41:11 andreas Exp $
|
||||
# Wait for heartbeat messages and act on them (or their absence)
|
||||
#
|
||||
import time, os, string, sys, socket, atexit, select, SocketServer, getopt
|
||||
import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal
|
||||
|
||||
False=0
|
||||
True=1
|
||||
@@ -30,6 +30,13 @@ msgw=None
|
||||
msgwB=None
|
||||
msgwHeight=10
|
||||
|
||||
def handler(signum, frame):
|
||||
global up, sig
|
||||
sig=signum
|
||||
if up == 0:
|
||||
return
|
||||
sys.exit(0)
|
||||
|
||||
class NullDevice:
|
||||
def write(self, s):
|
||||
pass
|
||||
@@ -249,14 +256,13 @@ def log(m, service="heartbeat"):
|
||||
def fromaddr(name, addr, boot, interval):
|
||||
global htab
|
||||
|
||||
if not htab.has_key(addr):
|
||||
if not hosts.has_key(name):
|
||||
addhost(name, addr)
|
||||
host=hosts[htab[addr]]
|
||||
if host.name != name:
|
||||
log("%s changed name to %s" % (host.name, name))
|
||||
del hosts[host.name]
|
||||
host.name=name
|
||||
hosts[name]=host
|
||||
host=hosts[name]
|
||||
if host.addr != addr:
|
||||
log("%s changed address to %s" % (host.name, addr))
|
||||
del htab[host.addr]
|
||||
host.addr=addr
|
||||
htab[addr]=name
|
||||
|
||||
host.lastbeat=now
|
||||
@@ -396,7 +402,9 @@ class HtmlHandler(SocketServer.BaseRequestHandler):
|
||||
res.append("<H2>Heartbeat status at %s</H2>" % time.strftime("%H:%M:%S", time.localtime(now)))
|
||||
res.append("<table>")
|
||||
res.append("<tr><th>Host</th><th>State</th><th>IP Addr</th><th>Res</th><th>Last change</th></tr>\n" )
|
||||
for h in hosts.keys():
|
||||
hosts_sorted=hosts.keys()
|
||||
hosts_sorted.sort()
|
||||
for h in hosts_sorted:
|
||||
res.append("<tr><td>%-24s</td><td>%-7s</td><td>%-16s</td><td>%-3s</td><td>%-17s</td></tr>\n" % (h, hosts[h].state, hosts[h].addr, hosts[h].uppercent, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hosts[h].statetime))))
|
||||
res.append("</table>")
|
||||
res.append("<P>")
|
||||
@@ -553,9 +561,14 @@ if not forground:
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
up=1
|
||||
sig=0
|
||||
signal.signal(signal.SIGTERM, handler)
|
||||
signal.signal(signal.SIGHUP, handler)
|
||||
|
||||
next=int(now)+1
|
||||
sleep=next - now
|
||||
while 1:
|
||||
while up:
|
||||
if visual:
|
||||
c = stdscr.getch()
|
||||
if c == ord('c'): msgs=[]; display()
|
||||
@@ -601,3 +614,6 @@ while 1:
|
||||
sleep=0
|
||||
if DEBUG: sys.stderr.write("sleep=%s next=%s\n" % (sleep, next))
|
||||
|
||||
|
||||
if sig == signal.SIGHUP:
|
||||
os.execv(sys.argv[0],sys.argv+['-R'])
|
||||
|
||||
Reference in New Issue
Block a user