#!/usr/bin/perl -w
# coded by Will Stockwell(waldo@cyberspace.org)
use CGI qw(:standard :html3 -no_debug);
use Time::CTime;
$dir = "."; #Directory location of output files
$refresh = 120; # Refresh rate of HTML page for browser
$hostfile = "hostlist";
$htmlfile = "linkstat.html";
$pingcnt = "3";
open(HOSTLIST, $hostfile) || die "Couldn't open $hostfile: $!";
@hostlist = <HOSTLIST>;
close(HOSTLIST);
open(HTMLOUT, ">$dir/$htmlfile") || die "Couldn't open $dir/$htmlfile:
+ $!";
print HTMLOUT "<HTML><HEAD><TITLE>Link Status</TITLE>",
"<META HTTP-EQUIV='refresh' CONTENT='$refresh; '>",
"</HEAD><BODY BGCOLOR='lightblue' TEXT='black'>",
h1("Link Status");
@headings = ('Node', 'Description', 'Status');
@rows = th(\@headings);
foreach (@hostlist) {
chomp;
/:/ || next; # Check for colon to be sure this is not a blank
+line
($host, $desc) = split(/:/);
$pingout = `/sbin/ping -c $pingcnt $host 2>&1`; # grab the pin
+g STDOUT and STDERR
open(PINGOUT, ">$dir/$host.html") || die "Couldn't open $dir/$
+host.html: $!";
$time = ctime(time());
print PINGOUT start_html(-BGCOLOR=>'lightblue',
-TEXT=>'black',
-title=>"Results of ping execution for
+ $host"),
h1("Results for $host at $time"),
p($desc);
foreach (split(/\n/, $pingout)) { print PINGOUT $_ . br; }
print PINGOUT end_html();
close(PINGOUT);
$host = a({-href=>"$host.html"}, "$host");
if($pingout =~ /unknown host/) { # This never shows when an IP
+ is not resolved
push(@rows, td([$host, $desc, "<FONT COLOR='brown'>Unresol
+ved IP</FONT>"]));
} elsif($pingout =~ /100% packet loss/) {
push(@rows, td([$host, $desc, "<FONT COLOR='red'>Down</FON
+T>"]));
} else {
push(@rows, td([$host, $desc, "<FONT COLOR='green'>Running
+</FONT>"]));
}
}
$email = a({-href=>"mailto:waldo\@cyberspace.org"}, "waldo\@cyberspace
+.org");
$time = ctime(time());
print HTMLOUT table({-border=>undef}, caption("Status check as of $tim
+e"), Tr(\@rows));
print HTMLOUT h5("Generated by linkstat.pl, coded by Will Stockwell($e
+mail)");
print HTMLOUT end_html();
close(HTMLOUT);
|