snmp monitoring[OT]
Subhendu Ghosh
sghosh at sghosh.org
Wed Feb 5 16:55:46 CET 2003
Attached is a cisco power/temp/fan monitor. It is going to be merged
with a similar juniper monitor and is not in the distrib as yet.
check_bgpstate in the contrib dir can monitor the bgp peering
relationships on any router.
-sg
On Wed, 5 Feb 2003, Atul Gosain wrote:
> Hi
>
> Im monitoring cisco server through Nagios. I have to monitor temperature
> and other environmental variables for cisco. Does somebody have an idea
> how can we enable environmental monitoring on cisco through SNMP. I
> searched a lot on cisco's site but could not find it.
> Also is there anyplugin written which monitors other aspects of cisco
> apart from interface status.
>
> Thanks
> Atul
>
>
--
-------------- 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