1
0
mirror of https://github.com/ranl/monitor-utils.git synced 2024-11-05 07:43:40 +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

@ -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 {