send ack with all packets

display host that support ack in upper case
This commit is contained in:
andreas
2012-03-29 00:04:34 +00:00
parent dd03128ed3
commit 4c3470c44d
2 changed files with 54 additions and 29 deletions
+31 -10
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# $Id: hbc,v 1.7 2007/04/05 15:51:13 andreas Exp $
import sys, time, socket, os, signal, getopt, string
# $Id: hbc,v 1.8 2012/03/29 00:04:34 andreas Exp $
import sys, time, socket, os, signal, getopt, string, select
PORT=50003
INTERVAL=10
@@ -116,6 +116,9 @@ if len(hb_hosts) == 0:
sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, \
sock.getsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR) | 1)
if verbose:
print "notice: hb_hosts: %s" % str(hb_hosts)
@@ -129,7 +132,8 @@ if not msgonly:
if len(msgboot) > 0:
msgboot.append("name=%s" % iam)
msgboot.append("time=%s" % time.time())
msg=string.join(msgboot,";")
msgboot.append("acks=0")
msg=";".join(msgboot)
while 1:
fail=0
for hb_host in hb_hosts:
@@ -168,22 +172,39 @@ if daemon:
up=1
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGHUP, handler)
ackcount=0
lastT=time.time()
while up:
try:
time.sleep(interval)
except:
break
sleep=(lastT+interval) - time.time()
if verbose: print "sleep %s" % sleep
if sleep > 0:
try:
r=select.select([sock.fileno()],[],[],sleep)
# time.sleep(interval)
except:
break
if verbose: print r
if sock.fileno() in r[0]:
data, addr = sock.recvfrom(1024)
if data == "ACK":
ackcount+=1
else:
try:
os.system(data)
except:
pass
continue
lastT=time.time()
for hb_host in hb_hosts:
try:
msg="interval=%s;name=%s;time=%s" % (interval, iam, time.time())
msg="interval=%s;name=%s;time=%s;acks=%s" % (interval, iam, time.time(), ackcount)
if verbose: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
sock.sendto(msg, (hb_host, hb_port))
except:
pass
up=0
msg="shutdown=1;name=%s" % (iam)
msg="shutdown=1;name=%s;acks=%s" % (iam, ackcount)
for hb_host in hb_hosts:
if verbose: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
sock.sendto(msg, (hb_host, hb_port))