I have a similar script that I posted, in a less refined form, some time ago.
The script that I wrote tests connectivity to a host outside of your
companies firewall, using an FTP proxy server to make the connection.

There are still imporvements that could be made, but this is not bad.

#!/bin/perl -w use Net::Telnet(); use Net::FTP(); use strict; unless (@ARGV) { print "\n\n\tUsage: pingtest.pl <name of calling script>\n\n"; exit(0); } chomp (my $CALLING_SCRIPT = "$ARGV[0]"); ###################################################################### +######### ### Note: this script only tests for hosts external to the Boeing netw +ork ### ### that are reached through a firewall + ### ###################################################################### +######### my $FIREWALL; my @FIREWALLS = qw (gate.somecompany.com othergate.somecompany.com); my @REACHABLE_FIREWALLS; my $REACHABLE_FIREWALL; my @USEABLE_FIREWALLS; my $USEABLE_FIREWALL; my @TOUCHABLE_FIREWALLS; my $TOUCHABLE_FIREWALL; my $FTP_SESSION; my $SUCCESSFUL_PROXY_CONNECTION = "none"; my $EXTERNAL_HOST = "192.xxx.185.xxx"; my $KEY = "default"; my @MESSAGE; umask 027; ###################################################################### +######### ### Beginning of main + ### ###################################################################### +######### @REACHABLE_FIREWALLS = pingFireWall(@FIREWALLS); @USEABLE_FIREWALLS = pingExternalHost(@REACHABLE_FIREWALLS); testFtpConnectivity(@USEABLE_FIREWALLS); print "$KEY $SUCCESSFUL_PROXY_CONNECTION"; if (($CALLING_SCRIPT eq "manualtest") or ($KEY ne "Working")) { `/opt/ECXpert_custom/scripts/notify.pl -k $KEY -s $CALLING_SCRIPT +\"@MESSAGE\" `; exit(2); } ###################################################################### +######### ### Beginning of subroutine sections + ### ###################################################################### +######### sub pingFireWall { @FIREWALLS = @_; foreach $FIREWALL (@FIREWALLS) { my $PINGFIREWALL = `/usr/sbin/ping \"$FIREWALL\"`; if ($PINGFIREWALL =~ /alive/) { push @MESSAGE, "Ping of $FIREWALL successful..."; $KEY = "Working"; push (@REACHABLE_FIREWALLS, $FIREWALL); } else { push @MESSAGE, "Ping of $FIREWALL failed!..."; $KEY = "Serious"; } } ### error check and notify section unless (@REACHABLE_FIREWALLS >= 1) { push @MESSAGE, "Unable to reach any Firewall servers!!..."; $KEY = "Critical"; } return(@REACHABLE_FIREWALLS); } sub pingExternalHost { my @LINES; my $LINE; my $T; @REACHABLE_FIREWALLS = @_; foreach $REACHABLE_FIREWALL (@REACHABLE_FIREWALLS) { $T = new Net::Telnet (Timeout => 20, Prompt => '/tination/'); $T->open("$REACHABLE_FIREWALL"); $T->waitfor('/tination/'); if ($T) { push @TOUCHABLE_FIREWALLS, $REACHABLE_FIREWALL; push @MESSAGE, "Telnet to $REACHABLE_FIREWALL successful.. +."; @LINES = $T->cmd("!ping $EXTERNAL_HOST"); $LINE ="@LINES"; if ($LINE =~ /alive/) { push @MESSAGE, "Ping of $EXTERNAL_HOST from $R +EACHABLE_FIREWALL sucessful..."; $KEY = "Working"; push @USEABLE_FIREWALLS, $REACHABLE_FIREWALL; } else { push @MESSAGE, "Ping of $EXTERNAL_HOST from $REACHABLE +_FIREWALL failed!..."; } } else { push @MESSAGE, "Telnet to $REACHABLE_FIREWALL failed!..."; push @MESSAGE, $LINE; $KEY = "Serious"; } } ### error check and notify section unless (@TOUCHABLE_FIREWALLS >= 1) { push @MESSAGE, "Cannot Telnet to either Firewall!!..." +; $KEY = "Critical"; } unless (@USEABLE_FIREWALLS >= 1) { $KEY = "Critical"; } return(@USEABLE_FIREWALLS); } sub testFtpConnectivity { @USEABLE_FIREWALLS = @_; foreach $USEABLE_FIREWALL (@USEABLE_FIREWALLS) { if ($FTP_SESSION = Net::FTP-> new("$USEABLE_FIREWALL", Debug = +> 0)) { $SUCCESSFUL_PROXY_CONNECTION = $USEABLE_FIREWALL; push @MESSAGE, "Ftp connection to $USEABLE_FIREWALL succes +sful..."; $KEY = "Working"; last; } else { push @MESSAGE, "Ftp connection to $USEABLE_FIREWALL failed +!!!..."; $KEY = "Serious"; } } ### error check and notify section unless ($SUCCESSFUL_PROXY_CONNECTION ne "none") { push @MESSAGE, "No FTP connections could be made!!!..."; $KEY = "Critical"; } return ($SUCCESSFUL_PROXY_CONNECTION); }
- cybear

In reply to Re: Simple Network Availability Monitor by cybear
in thread Simple Network Availability Monitor by Massyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.