#!/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 = ; close(HOSTLIST); open(HTMLOUT, ">$dir/$htmlfile") || die "Couldn't open $dir/$htmlfile: $!"; print HTMLOUT "Link Status", "", "", 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 ping 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, "Unresolved IP"])); } elsif($pingout =~ /100% packet loss/) { push(@rows, td([$host, $desc, "Down"])); } else { push(@rows, td([$host, $desc, "Running"])); } } $email = a({-href=>"mailto:waldo\@cyberspace.org"}, "waldo\@cyberspace.org"); $time = ctime(time()); print HTMLOUT table({-border=>undef}, caption("Status check as of $time"), Tr(\@rows)); print HTMLOUT h5("Generated by linkstat.pl, coded by Will Stockwell($email)"); print HTMLOUT end_html(); close(HTMLOUT);