Ag3NT has asked for the wisdom of the Perl Monks concerning the following question:

I'm kinda new to Perl so bear with me. I'm trying to write a perl script that will actively monitor network links from an NT server and make reports in a graphical manner to a web page that is set to refresh every so often (so someone viewing the page doesn't have to reload the page). I've seen some scripts that do almost all of what I want, but they are for *nix. I'm not sure how to mod them to run on NT or what modules I'd need to make this work. Can anyone help me out? Ag3NT

Replies are listed 'Best First'.
Re: Link Status
by Biker (Priest) on Jan 24, 2002 at 13:28 UTC

    Short answer: no.
    Long answer: Yes, of course. With pleasure.

    But you will have to do the main work yourself. When you have a specific question, post it here. No one will be happy to do the work for you (unless payed for it ;-).

    Do as much as you can yourself. When you stumble over something that you're unable to solve, post your specific problem here. Include the code that doesn't work the way you expect it to.

    Lastly, you will get more help if it's obvious that you have made a serious effort to solve it yourself.

    "Livet är hårt" sa bonden.
    "Grymt" sa grisen...

Re: Link Status
by Ag3NT (Initiate) on Jan 25, 2002 at 05:24 UTC
    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

      ...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