1
0
mirror of https://github.com/ranl/monitor-utils.git synced 2024-11-22 07:23:42 +01:00

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
This commit is contained in:
Retakfual 2016-04-18 23:05:53 +02:00 committed by Ran Leibman
parent c1026dfa5e
commit 8c7a75d976

View File

@ -93,14 +93,20 @@ my %int_status_index = (
### Functions ### 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 { sub _create_session {
my ($server, $comm) = @_; my ($server, $comm) = @_;
my $version = 1; my $version = 1;
my ($sess, $err) = Net::SNMP->session( -hostname => $server, -version => $version, -community => $comm); 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; return $sess;
} }
@ -193,10 +199,7 @@ if($check_type =~ /^temp/) {
last; last;
} }
if("$temp" eq "") { check_oid_return($temp, $check_type);
print "The switch $switch can't report temperature via SNMP\n";
FSyntaxError();
}
if($temp > 1) { if($temp > 1) {
if($warn > $crit and "$check_type") { 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_free = "$R_mem_free->{$S_mem_free}";
my $mem_total = $mem_free + $mem_used; 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_used = int($mem_used / 1024 / 1024);
$mem_free = int($mem_free / 1024 / 1024); $mem_free = int($mem_free / 1024 / 1024);
$mem_total = int($mem_total / 1024 / 1024); $mem_total = int($mem_total / 1024 / 1024);
my $mem_free_perc = int($mem_free / $mem_total * 100); my $mem_free_perc = int($mem_free / $mem_total * 100);
if($mem_free_perc > $warn) { 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 $R_load_5m = $snmp_session->get_request(-varbindlist => [$S_load_5m]);
my $load_5m = "$R_load_5m->{$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) { if($load_5s <= $warn) {
$stat = 0; $stat = 0;
$msg = "Cpu: OK - Cpu Load $load_5s% $load_1m% $load_5m%"; $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) { if($total_err != 0) {
$err_msg = ", $err_msg have an error"; $err_msg = ", $err_msg have an error";
} else { } else {