my ( $session, $error ) = (); ( $session, $error ) = Net::SNMP->session( -version => 'SNMPv2', -hostname => $origin_ip, -community => $community, -port => 161, -timeout => 3, -debug => 0, -retries => 2, ); # First we check if the PING-MIB instance is already set up. # Normally it should be. my $check_if_set_up = (); $check_if_set_up = $session->get_request( -varbindlist => [$pingCtlRowStatus] ); if ( !defined($check_if_set_up) ) { printf( "ERROR (Check_if_set_up): %s.\n", $error ); exit 1; } if ( $check_if_set_up->{$pingCtlRowStatus} ne 1 ) { # Let's make sure that the pingMaxConcurrentRequests is high enough. my $setup_maxconcurr = (); $setup_maxconcurr = $session->set_request( -varbindlist => [ $pingMaxConcurrentRequests,INTEGER,30 ]); # If it is NOT set up then let's do that now. my $setup_probes_session = (); $setup_probes_session = $session->set_request( -varbindlist => [@set_oids] ); if ( !defined($setup_probes_session) ) { printf( "ERROR (Setup_probes_session): %s.\n", $error ); exit 1; } } else { # Otherwise we should just get the results. my $get_responses = $session->get_request( -varbindlist => [@get_oids] ); # if ( !defined($get_responses) ) { my $err = $session->error; print "ERROR: $err\n"; $session->close(); exit 1; } # Here we will get the History table for the last 5 ICMP requests and see if any were not successfull. my $get_history = 0; $get_history = $session->get_entries( -columns => ["$pingProbeHistoryStatus\.$fulltargetname"] ); if ( !defined($get_history) ) { my $err = $session->error; print "$err\n"; $session->close(); exit 1; } # Here we calculate the number of bad responses. my $err = 0; while ( my ( $oid, $value ) = each %$get_history ) { # 1 is a plain old failure. 9 is when the max concurrency set above has been exceeded. # This is not an error so let's ignore that too... if ( $value !~ /1|9/ ) { $err++; } } # Set the ErrorCode and ErrorMessage my ( $errorcode, $errormessage ); if ( $err != 0 ) { $errorcode = "1"; $errormessage = "$err errors"; } else { $errorcode = "0"; $errormessage = "All OK"; }