From 8c7a75d976359fd31df69b5e49b0572ff6010487 Mon Sep 17 00:00:00 2001 From: Retakfual Date: Mon, 18 Apr 2016 23:05:53 +0200 Subject: [PATCH] Update check-cisco.pl (#23) the check for a valide session in _create_session was not working, because $sess was always filled with an hash value even, if there was no session created. I deleted this part instead I created the function check_oid_return, which returns an error if snmp does not give back any value regarding to the checked oid --- nagios/check-cisco.pl | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/nagios/check-cisco.pl b/nagios/check-cisco.pl index 5544642..8e3f979 100755 --- a/nagios/check-cisco.pl +++ b/nagios/check-cisco.pl @@ -56,8 +56,8 @@ my %phy_dev_status = ( 2 => 'warning', 3 => 'critical', 4 => 'shutdown', - 5 => 'notPresent', - 6 => 'notFunctioning', + 5 => 'not Present', + 6 => 'not Functioning', ); my %module_status_code = ( 1 => 'unknown', @@ -93,14 +93,20 @@ my %int_status_index = ( ### Functions ############### +sub check_oid_return { + my ($oid_value, $parameter_name) = @_; + + if ( $oid_value == '' ) { + print "Remote device does not return data for $parameter_name\n"; + exit(1); + } +} + sub _create_session { my ($server, $comm) = @_; my $version = 1; my ($sess, $err) = Net::SNMP->session( -hostname => $server, -version => $version, -community => $comm); - if (!defined($sess)) { - print "Can't create SNMP session to $server\n"; - exit(1); - } + return $sess; } @@ -193,10 +199,7 @@ if($check_type =~ /^temp/) { last; } - if("$temp" eq "") { - print "The switch $switch can't report temperature via SNMP\n"; - FSyntaxError(); - } + check_oid_return($temp, $check_type); if($temp > 1) { if($warn > $crit and "$check_type") { @@ -238,10 +241,16 @@ if($check_type =~ /^temp/) { my $mem_free = "$R_mem_free->{$S_mem_free}"; my $mem_total = $mem_free + $mem_used; + + check_oid_return($mem_used, $check_type); + check_oid_return($mem_free, $check_type); + + $mem_used = int($mem_used / 1024 / 1024); $mem_free = int($mem_free / 1024 / 1024); $mem_total = int($mem_total / 1024 / 1024); + my $mem_free_perc = int($mem_free / $mem_total * 100); if($mem_free_perc > $warn) { @@ -306,6 +315,10 @@ if($check_type =~ /^temp/) { my $R_load_5m = $snmp_session->get_request(-varbindlist => [$S_load_5m]); my $load_5m = "$R_load_5m->{$S_load_5m}"; + check_oid_return($load_5s, $check_type); + check_oid_return($load_1m, $check_type); + check_oid_return($load_5m, $check_type); + if($load_5s <= $warn) { $stat = 0; $msg = "Cpu: OK - Cpu Load $load_5s% $load_1m% $load_5m%"; @@ -339,6 +352,11 @@ if($check_type =~ /^temp/) { } } + if($sum == 0) { + print "fan: CRIT - No Fans are running\n"; + exit(1); + } + if($total_err != 0) { $err_msg = ", $err_msg have an error"; } else {