From d227eea1d6ca0f74ea17f020cacc32ec0701c736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Fr=C3=BChwirth?= Date: Mon, 19 Sep 2016 10:07:42 +0200 Subject: [PATCH] check_fortigate.pl: Return OK in case of no configured VPN tunnels In case of zero configured tunnels $oid_ipsectuntableroot does not exist which resulted in the script exiting with UNKNOWN: session get table failed for .1.3.6.1.4.1.12356.101.12.2.2.1.1 --- fortigate/check_fortigate.pl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fortigate/check_fortigate.pl b/fortigate/check_fortigate.pl index d6edef9..7ceea7e 100755 --- a/fortigate/check_fortigate.pl +++ b/fortigate/check_fortigate.pl @@ -492,7 +492,7 @@ sub get_vpn_state { if ($vpnmode ne "ssl") { # N/A as of 2015 # # Get just the top level tunnel data - my %tunnels = %{get_snmp_table($session, $oid_ipsectuntableroot . $oidf_tunndx)}; + my %tunnels = %{get_snmp_table_nodie($session, $oid_ipsectuntableroot . $oidf_tunndx)}; while (($oid, $value) = each (%tunnels)) { #Bump the total tunnel count @@ -694,6 +694,19 @@ sub get_snmp_table{ return $sess_get_table; } # end get snmp table +sub get_snmp_table_nodie{ + my $session = $_[0]; + my $oid = $_[1]; + + my $sess_get_table = $session->get_table( + -baseoid =>$oid + ); + + if ( ! defined($sess_get_table) ) { + return {}; + } + return $sess_get_table; +} # end get snmp table sub parse_args { my $ip = ""; # snmp host