Files
heartbeat/mlog.cgi
T
2013-07-14 14:50:04 -04:00

59 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
import string, os
VER = "mlog 1.00"
hosts = ["weekend", "wingbat"]
URI = "/~andreas/private/mlog.cgi?"
print "Content-type: text/html"
print "max-age: 0"
print "expires: 0"
print "pragma: no-cache"
print ""
print "<HTML>"
print "<HEAD>"
print "<TITLE>"
print "Motion Log"
print "</TITLE>"
print "<H2>Motion Log</H2>"
print "</HEAD>"
print '<BODY BGCOLOR="#FFFFFF" LINK="#008000" VLINK="#008000" BACKGROUND="/~andreas/images/tile.marble.gif">'
print "<pre>"
def hstlines(host):
cmd = "/sbin/ping -c 1 -w 2 %s 2>&1 >/dev/null" % host
r = os.system(cmd)
if r == 0:
p = os.popen("rsh %s tail -200 .heyu/logs/motion.log | grep -v again | tail -32" % host, "r")
l = p.readlines()
else:
l = ["<B>Host %s is unreachable</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" % host]
return l
rep = []
for host in hosts:
rep.append(hstlines(host))
print '<table cellpading="0" cellspacing="0" border="0" style="color:black;text-align:left">'
i = 0
print "<tr><th>%s</th></tr>" % string.join(hosts, '</th><th>')
while 1:
line = []
f = 0
for h in rep:
try:
line.append(h[i][:-1])
f = 1
except:
line.append("")
if f == 0:
break
print "<tr><td>%s</td></tr>" % string.join(line, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>')
i += 1
print '</table></pre>'
execfile("/home/andreas/cgi-bin/trailer.py")