Software to monitor constant connectivity

Bambi

I Cleaned My Room - And I am a Dude
Joined
Jun 9, 2003
Messages
2,225
Is there a piece of software which exist which will allow to install it on one of the systems at work, and ping a site or something for 24 hours straight. We recently had a new customized database installed with an online vnc portion, but the vnc seems to go out at nights so i wanted to try a test.
 
if you want to go simple, "ping -t". I wrote a little Perl script that I use as our secondary monitoring.. it does both a ping and a snmp uptime check of all of our network devices, and sends out an email if one is down or the uptime is less than x minutes.
 
That is cool Fint... can you post the script?? Or is it a trade secret? :D

Ugh.. its not a trade secret, but I'm a network admin, not a programmer, so my code is U-G-L-Y. Its likely got security problems, performance problems, sanity problems, and may break your toaster and cause your dog to get mange, I'm not responsible for damage it might cause. It works great for me, but your mileage may vary.

Its in three-parts. Part one is the main script, here:

Code:
#!/usr/bin/perl -w
# by Fint @ [H]ardforum
# simple network-monitoring script; designed to be ran by cron
# with no output being good, and any output being
# bad (and thus, cron will email it to you)
# I know it is ugly, I'm not a coder by profession
#
# Version 5: don't spam when low uptimes
# Version 4: added opt-out of snmpget
# Version 3: added return code checking to snmpgets
# Version 2: added snmpgets of uptime value
# Version 1: initial version
#
# usage:
# router-check.pl IP-OF-ROUTER-HERE SNMP-STRING-HERE
# i.e.
# router-check.pl 172.16.0.1 public
# To disable uptime check, use snmp community of 'NONE'
# defaults to use SNMP version 1; list snmp version after string to use a diff one


# uncomment for chatty debugging
#$DEBUG = 1;
$DOWNNOTICELOG = "/tmp/bwrcstatus";
$UPTIME = 5;

if ($DEBUG) {$DOWNNOTICELOG = "$DOWNNOTICELOG.test"}

unless (-e $DOWNNOTICELOG) {system("mkdir $DOWNNOTICELOG");}

if (!$ARGV[0]) {
die "no host to check";}

if (!$ARGV[1]) {
 if ($DEBUG) {print "DEBUG: no snmp community given; assuming 'public'\n";}
 $snmpcom = "public";}
 else {$snmpcom = $ARGV[1];}

if (!$ARGV[2]) {
 if ($DEBUG) {print "DEBUG: no snmp version given; assuming ver1\n";}
 $snmpver = "1" }
 else {$snmpver = $ARGV[2];}

my $ping = system("ping -A -c 3 $ARGV[0] > /dev/null");
my $pingrc = ($ping >> 8) & 0xff;

if ($DEBUG) {print "DEBUG: ping return code was $pingrc     0=good 1=bad\n";}

if (($pingrc == 0) & ($snmpcom eq "NONE")) {
if ($DEBUG) {print "DEBUG: ping was good, snmpcom set to NONE, all done\n";}
exit;
}

# ping was successful, do snmp uptime check
if ($pingrc == 0) {

  if (-e "$DOWNNOTICELOG/$ARGV[0].ping") {
     if ($DEBUG) {print "DEBUG: ping is good, deleting log file $DOWNNOTICELOG/$ARGV[0].ping\n";}
     print "Host $ARGV[0] is now pingable\n";
     system("rm $DOWNNOTICELOG/$ARGV[0].ping");}



   my $snmpcheck = `snmpget -Ovt -v $snmpver -r 2 -c $snmpcom $ARGV[0] .1.3.6.1.2.1.1.3.0 2>/dev/null`;
   my $snmpcheckrc = ($? >> 8);
   chomp $snmpcheck;
   if ($DEBUG) {print "DEBUG: snmpget rc was $snmpcheckrc   0=good 1=bad\n";}
   if ($DEBUG) {print "DEBUG: snmpget returned $snmpcheck\n";}
      # only do time calc if snmpget was successful
   if ($snmpcheckrc == 0) {
           # 100 ticks = 1 second       90000 ticks = 15 minutes
           $uptimeminutes= $snmpcheck / 100 / 60;
           if ($uptimeminutes < $UPTIME) { # actual uptime is less than desired
                   if ($DEBUG) {print "DEBUG: uptime is $uptimeminutes minutes\n";}
                      if (-e "$DOWNNOTICELOG/$ARGV[0].uptime") {if ($DEBUG) {print "DEBUG: uptime is low, but alert file already exists\n";}}
                   else { # uptime is low, no alerts sent yet
                        {print "Host $ARGV[0] uptime reported as $uptimeminutes minutes\n";}
                        if ($DEBUG) {print "DEBUG: uptime is low, no file exists, creating file $DOWNNOTICELOG/$ARGV[0].uptime\n";}
                        system("touch $DOWNNOTICELOG/$ARGV[0].uptime");}
                        }
           else {
                if ($DEBUG) {print "DEBUG: everything is ok, uptime is $uptimeminutes minutes\n";}
                if (-e "$DOWNNOTICELOG/$ARGV[0].uptime") {
                        if ($DEBUG) {print "DEBUG: uptime is good, deleting log file $DOWNNOTICELOG/$ARGV[0].uptime\n";}
                        print "Host $ARGV[0] uptime is now good at $uptimeminutes minutes\n";
                        system("rm $DOWNNOTICELOG/$ARGV[0].uptime");}
                else {
                        if ($DEBUG) {print "DEBUG: uptime is good, no log file $DOWNNOTICELOG/$ARGV[0].uptime exists\n";}
         }
   }}
   else { # snmpget failed
        if (-e "$DOWNNOTICELOG/$ARGV[0].uptime") {
                if ($DEBUG) {print "DEBUG: failed snmpget, log file $DOWNNOTICELOG/$ARGV[0].uptime exists, no alerting\n";}
                }
        else {
                if ($DEBUG) {print "DEBUG: failed snmpget, no file exists, creating file $DOWNNOTICELOG/$ARGV[0].uptime\n";}
                system("touch $DOWNNOTICELOG/$ARGV[0].uptime");
                print "Host $ARGV[0] failed snmpget\n";}
        }
} # ping failed
else {
        if (-e "$DOWNNOTICELOG/$ARGV[0].ping") {
                if ($DEBUG) {print "DEBUG: failed ping, log file $DOWNNOTICELOG/$ARGV[0].ping exists, no alerting\n";}
                }
        else {
                if ($DEBUG) {print "DEBUG: failed ping, no file exists, creating file $DOWNNOTICELOG/$ARGV[0].ping\n";}
                system("touch $DOWNNOTICELOG/$ARGV[0].ping");
                print "Host $ARGV[0] failed ping test\n";}

}


The script is called by a job that runs from cron (part 2), like this:

Code:
fint@wh-mon06:~$ crontab -l
* * * * *       /home/fint/bw-router-check.sh
* * * * *       /usr/bin/find /tmp/bwrcstatus/ -type f -mmin +60 -exec rm {} \;
* * * * *       /usr/bin/find /tmp/bwrcstatus/ -type f -iname "*.ping" -mmin +5 -exec rm {} \;

The only file you'll really need to modify (part 3) looks like:

Code:
#!/bin/sh
perl /home/fint/perl/router-check.pl 192.168.222.24 swread
perl /home/fint/perl/router-check.pl 192.168.222.25 swread

# Datacenter switch
perl /home/fint/perl/router-check.pl 192.168.144.5 ffi-public

# cisco Wireless Lan Controller
perl /home/fint/perl/router-check.pl 192.168.222.12 ffi-public 2c


Anyways, hope somebody finds it useful. I accept patches, feedback, and feature requests. Maybe if I get really bored I'll write a web GUI for it ;-)
 
Back
Top