in reply to Link Status

This is what I have so far. I found the initial code here at the monastary. I've modded everything to work with Win2000, and it works without errors now.
#c:\\perl\\bin #coded for Windows 2000 by Cpl Steve Taylor 1stMarDiv G-6 DSN 365-3499 use CGI qw(:standard :html3 -no_debug); use Time::CTime; $dir = "c:"; #Directory location of output files $refresh = 10; # Refresh rate of HTML page for browser $hostfile = "c:\\hostlist.txt"; $htmlfile = "linkstat.html"; $pingcnt = "2"; open(HOSTLIST, $hostfile) || die "Couldn't open $hostfile: $!"; @hostlist = <HOSTLIST>; close(HOSTLIST); open(HTMLOUT, ">$dir\\$htmlfile") || die "Couldn't open $dir\\$htmlfil +e: $!"; print HTMLOUT "<HTML><HEAD><TITLE>1st Marine Division Link Status</TIT +LE>", "<META HTTP-EQUIV='refresh' CONTENT='$refresh; '>", "</HEAD><BODY BGCOLOR='white' TEXT='black'>"; print HTMLOUT "<h1><center>1st Marine Division Link Status</center></h +1>"; @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 = `c:\\winnt\\system32\\ping -n $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=>'white', -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>"])); } } $time = ctime(time()); print HTMLOUT table({-border=>undef}, caption("Status check as of $tim +e"), Tr(\@rows)); print HTMLOUT a({-href=>"mailto:webmaster\@1mardiv.usmc.mil"}, "webmas +ter\@1mardiv.usmc.mil"); print HTMLOUT end_html(); close(HTMLOUT);
Now I have a new question. Is it possible to do this (monitor link status) using SNMP. If so how involved would it be? I've looked at using some different SNMP modules but am confused as to which one to use. Ag3NT

Replies are listed 'Best First'.
Re: Re: Link Status
by Zaxo (Archbishop) on Jan 25, 2002 at 08:23 UTC

    ...I found the initial code here at the monastary. I've modded everything to work with Win2000, and it works without errors now.
    Plese update this node to attribute the original author and link to the original code.

    Update: Rereading this, I realized it sounded a mite abrupt, sorry. Attribution is a necessary courtesy, even though the code posted here is intended to be modified and reused just as you have done. A link to the original code would provide an example to other monks with NT translation problems.

    After Compline,
    Zaxo