Monitoring Cisco Routers

Subhendu Ghosh sghosh at sghosh.org
Thu Mar 20 14:12:46 CET 2003


On Thu, 20 Mar 2003, Jens Kruse wrote:

> Hi -sg, hi *,
> 
> Subhendu Ghosh wrote:
> >> Is there a way to monitor link states, interface states, processor load
> >>etc on Cisco routers? I'm assuming this would have to be done using
> >>check_snmp. If that's how it's done, does anyone have any MIB's or link
> >>to a resource that could get me started? Of course, there is always the
> >>jackpot, has anyone made any plugins for Cisco kit ;-)
> > ...
> > check_ifstatus for monitoring individual interfaces
> > check_ifoperstatus for monitoring all interfaces
> > contrib/checkciscotemp for monitoring cisco temp..
> 
> Has anyone already realiszed other plugins for Cisco devices, i.e. Cisco 
> Pix?
> Or plugins which already handle load and other/more details on Cisco 
> Machines?
> 
> I have to monitor a big nummer of Cisco Machnies in the future, but 
> don't know much about SNMP.
> 
> Does anyone have a hint or some examples how to monitor such things with 
> check_snmp?
> 
> Any cooking recipe is welcome!
> 
> Thanks, Jens
> 

Attached is check_cisco_env (from Guy) to monitor temp,voltage,fan,cpu.

Plans are to merge this with a similar plugin for Juniper that Guy also 
wrote.  We could probably add a memory utilization relatively easily.


Are there any particular thigs that you want to see monitored (or see if 
it possible to monitor)?


-- 

-sg
-------------- next part --------------
#!/usr/bin/perl -wT
#
# check_xinterface - nagios plugin 
#
# largely based upon check_ifoperstatus.pl plugin by Christoph Kron
# 
#
#
#
# Copyright (C) 2002 Guy Van Den Bergh
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
#
# Report bugs to: guy at belnet.be
#

# design of the plugin:
#  check admin status: if down, then warning; exit
#  check operational status: if down, then critical; exit
#  check last change, if within 'tolerance' (-l or --last-change option),
#    then warning
#  get performance data: bits in/out, etc... (implementation to be scheduled later)
#  performance data could be checked against older values (bw drops e.g.)

use strict;

use Net::SNMP;
use Getopt::Long;
&Getopt::Long::config('auto_abbrev');


my $status;
my $TIMEOUT = 60;

my %ERRORS = ('UNKNOWN' , '-1',
              'OK' , '0',
              'WARNING', '1',
              'CRITICAL', '2');

my %ciscoEnvMonState = 	('1','normal(1)',
			 '2','warning(2)',
			 '3','critical(3)',
			 '4','shutdown(4)',
			 '5','notPresent(5)',
			 '6','notFunctioning(6)');

my $state = "UNKNOWN";
my $answer = "";
my $snmpkey = 1;
my $community = "public";
my $port = 161;
my $t_oid;
my @snmpoids;
my %error_oids;
my $snmpCiscoVoltageStatus;
my $snmpCiscoTemperatureStatus;
my $snmpCiscoFanStatus;
my $snmpCiscoSupplyStatus;
my $hostname;
my $session;
my $error;
my $response;
my $value;
my $oid;
my @voltage_errors;
my @temperature_errors;
my @fan_errors;
my @supply_errors;


sub usage {
  printf "\nMissing arguments!\n";
  printf "\n";
  printf "Perl Check Cisco Environment plugin for Nagios\n";
  printf "checks status of temperature, fans, ...\n";
  printf "usage: \n";
  printf "check_cisco_env -c <READCOMMUNITY> -p <PORT> <HOSTNAME>";
  printf "\nCopyright (C) 2002 Guy Van Den Bergh\n";
  printf "check_cisco_env comes with ABSOLUTELY NO WARRANTY\n";
  printf "This programm is licensed under the terms of the ";
  printf "GNU General Public License\n(check source code for details)\n";
  printf "\n\n";
  exit $ERRORS{"UNKNOWN"};
}

# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
     print ("ERROR: No snmp response from $hostname (alarm)\n");
     exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);


$status = GetOptions("community=s",\$community,
                     "port=i",\$port);
if ($status == 0)
{
        &usage;
}
  
   #shift;
   $hostname  = shift || &usage;

   ($session, $error) = Net::SNMP->session(
      -hostname  => $hostname,
      -community => $community,
      -port      => $port
   );

   if (!defined($session)) {
      $state='UNKNOWN';
      $answer=$error;
      print ("$state: $answer");
      exit $ERRORS{$state};
   }

   $snmpCiscoVoltageStatus = '.1.3.6.1.4.1.9.9.13.1.2.1.7';
   $snmpCiscoTemperatureStatus = '.1.3.6.1.4.1.9.9.13.1.3.1.6';
   $snmpCiscoFanStatus = '.1.3.6.1.4.1.9.9.13.1.4.1.3';
   $snmpCiscoSupplyStatus = '.1.3.6.1.4.1.9.9.13.1.5.1.3';


   push(@snmpoids,$snmpCiscoVoltageStatus);
   push(@snmpoids,$snmpCiscoTemperatureStatus);
   push(@snmpoids,$snmpCiscoFanStatus);
   push(@snmpoids,$snmpCiscoSupplyStatus);
   #
   # These four oids all have the same syntax,
   # which makes it easy for scripting all four oids at the same time!
   #

   $answer = "No data returned (Environment MIB not supported)";
   # This will be overwritten when there IS data returned!

   TABLE:
   foreach $t_oid (@snmpoids) {
   #
   # Now get all relevant oids, and set the plugin output status accordingly.
   #

      if (!defined($response = $session->get_table($t_oid))) {
         $error_oids{$t_oid} = $session->error;
         next TABLE;
      }

      while ( ($oid, $value) = each %$response ) {

         if ($value == 1 || $value == 5 || $value == 6) {
           # normal, notPresent or notFunctioning
           $state = 'OK' if $state =~ /UNKNOWN/;
           $answer = "All environment variables normal." if $state eq 'OK';
         } elsif ($value == 2) {
           # warning
	   $error_oids{$oid} = $ciscoEnvMonState{$value};
           $state = 'WARNING' unless $state =~ /CRITICAL/;
         } elsif ($value == 3 || $value == 4) {
           # critical or shutdown
           $error_oids{$oid} = $ciscoEnvMonState{$value};
           $state = 'CRITICAL'
         }

      }
   }

   $session->close;

## Here is the place for introducing artificial errors (for debugging).


#
# Now parse all erroneous responses:
#

unless ($state eq 'OK' or $state eq 'UNKNOWN') {

   while ( ($oid, $value) = each %error_oids ) {

      $value =~ s/\(\d\)//;

      if ($oid =~ /$snmpCiscoVoltageStatus\./) {
         $oid =~ s/$snmpCiscoVoltageStatus\.//;
         push(@voltage_errors, "$value (instance $oid)");

      } elsif($oid =~ /$snmpCiscoTemperatureStatus\./) {
         $oid =~ s/$snmpCiscoTemperatureStatus\.//;
         push(@temperature_errors, "$value (instance $oid)");

      } elsif ($oid =~ /$snmpCiscoFanStatus\./) {
         $oid =~ s/$snmpCiscoFanStatus\.//;
         push(@fan_errors, "$value (fan $oid)");

      } elsif ($oid =~ /$snmpCiscoSupplyStatus\./) {
         $oid =~ s/$snmpCiscoSupplyStatus\.//;
         push(@supply_errors, "$value (PS $oid)");
      }
   }

   #
   # And now the final formatting of the output:
   #

   my $voltage_errors_s = join ";", @voltage_errors if defined $voltage_errors[0];
   my $temperature_errors_s = join ";", @temperature_errors if defined $temperature_errors[0];
   my $fan_errors_s = join ";", @fan_errors if defined $fan_errors[0];
   my $supply_errors_s = join ";", @supply_errors if defined $supply_errors[0];

   $answer = "Problems with:<BR>";
   $answer .= "Voltage: " . $voltage_errors_s . "<BR>" if defined $voltage_errors_s;
   $answer .= "Temperature: " . $temperature_errors_s . "<BR>" if defined $temperature_errors_s;
   $answer .= "Fans: " . $fan_errors_s . "<BR>" if defined $fan_errors_s;
   $answer .= "Power Supply: " . $supply_errors_s ."<BR>" if defined $supply_errors_s;
}

print ("$answer\n");
exit $ERRORS{$state};



More information about the Users mailing list