From 5416a440034507c43aa121dde54600fb62667d79 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 09:17:08 +0100 Subject: [PATCH] update vpn-status checkpoint --- network/checkpoint/snmp/mode/connections.pm | 5 +- network/checkpoint/snmp/mode/cpu.pm | 10 +-- network/checkpoint/snmp/mode/vpnstatus.pm | 77 ++++++++++++--------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/network/checkpoint/snmp/mode/connections.pm b/network/checkpoint/snmp/mode/connections.pm index e0141c3cc..90adbcc9c 100644 --- a/network/checkpoint/snmp/mode/connections.pm +++ b/network/checkpoint/snmp/mode/connections.pm @@ -29,7 +29,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'warning:s' => { name => 'warning' }, 'critical:s' => { name => 'critical' }, @@ -65,7 +65,7 @@ sub run { my $oid_fwNumCom = '.1.3.6.1.4.1.2620.1.1.25.3.0'; my $oid_fwConnTableLimit = '.1.3.6.1.4.1.2620.1.1.25.10.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_fwNumCom, $oid_fwConnTableLimit], nothing_quit => 1); - + my $value = $result->{$oid_fwNumCom}; my $extra = ''; my %total_options = (); @@ -78,7 +78,6 @@ sub run { } } - my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add( diff --git a/network/checkpoint/snmp/mode/cpu.pm b/network/checkpoint/snmp/mode/cpu.pm index 5759d6587..d34127b0d 100644 --- a/network/checkpoint/snmp/mode/cpu.pm +++ b/network/checkpoint/snmp/mode/cpu.pm @@ -29,7 +29,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'warning:s' => { name => 'warning', }, 'critical:s' => { name => 'critical', }, @@ -41,7 +41,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); @@ -59,11 +59,11 @@ sub run { my $oid_procUsrTime = '.1.3.6.1.4.1.2620.1.6.7.2.1.0'; my $oid_procSysTime = '.1.3.6.1.4.1.2620.1.6.7.2.2.0'; my $oid_procIdleTime = '.1.3.6.1.4.1.2620.1.6.7.2.3.0'; - + my $result = $self->{snmp}->get_leef(oids => [$oid_procUsrTime, $oid_procSysTime, $oid_procIdleTime], nothing_quit => 1); - + my $totalCpuUsed = $result->{$oid_procUsrTime} + $result->{$oid_procSysTime}; - + my $exit = $self->{perfdata}->threshold_check(value => $totalCpuUsed, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, diff --git a/network/checkpoint/snmp/mode/vpnstatus.pm b/network/checkpoint/snmp/mode/vpnstatus.pm index e9fae20d9..08c42fa21 100644 --- a/network/checkpoint/snmp/mode/vpnstatus.pm +++ b/network/checkpoint/snmp/mode/vpnstatus.pm @@ -24,48 +24,50 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; -} -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; - return 0; + return 'status : ' . $self->{result_values}->{status}; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, { name => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All vpn are ok' } ]; - + + $self->{maps_counters}->{global} = [ + { label => 'tunnels-total', nlabel => 'vpn.tunnels.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'current total number of tunnels: %d', + perfdatas => [ + { value => 'total_absolute', template => '%d', min => 0 } + ] + } + } + ]; + $self->{maps_counters}->{vpn} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'type' }, { name => 'status' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'warning-status:s' => { name => 'warning_status', default => '' }, @@ -73,7 +75,7 @@ sub new { 'filter-name:s' => { name => 'filter_name' }, 'buggy-snmp' => { name => 'buggy_snmp' }, }); - + return $self; } @@ -86,37 +88,42 @@ sub check_options { sub prefix_vpn_output { my ($self, %options) = @_; - + return "VPN '" . $options{instance_value}->{display} . "' "; } -my %map_type = (1 => 'regular', 2 => 'permanent'); -my %map_state = (3 => 'active', 4 => 'destroy', 129 => 'idle', 130 => 'phase1', +my $map_type = { 1 => 'regular', 2 => 'permanent' }; +my $map_state = { + 3 => 'active', 4 => 'destroy', 129 => 'idle', 130 => 'phase1', 131 => 'down', 132 => 'init' -); +}; my $mapping = { tunnelPeerObjName => { oid => '.1.3.6.1.4.1.2620.500.9002.1.2' }, - tunnelState => { oid => '.1.3.6.1.4.1.2620.500.9002.1.3', map => \%map_state }, - tunnelType => { oid => '.1.3.6.1.4.1.2620.500.9002.1.11', map => \%map_type }, + tunnelState => { oid => '.1.3.6.1.4.1.2620.500.9002.1.3', map => $map_state }, + tunnelType => { oid => '.1.3.6.1.4.1.2620.500.9002.1.11', map => $map_type } }; my $oid_tunnelEntry = '.1.3.6.1.4.1.2620.500.9002.1'; sub manage_selection { my ($self, %options) = @_; - $self->{vs} = {}; my $snmp_result; if (defined($self->{option_results}->{buggy_snmp})) { $snmp_result = $options{snmp}->get_table(oid => $oid_tunnelEntry, nothing_quit => 1); } else { - $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $mapping->{tunnelPeerObjName}->{oid} }, - { oid => $mapping->{tunnelState}->{oid} }, - { oid => $mapping->{tunnelType}->{oid} }, - ], nothing_quit => 1, return_type => 1); + $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_tunnelEntry, start => $mapping->{tunnelPeerObjName}->{oid}, end => $mapping->{tunnelState}->{oid} }, + { oid => $mapping->{tunnelType}->{oid} } + ], + nothing_quit => 1, + return_type => 1 + ); } + $self->{global} = { total => 0 }; + $self->{vs} = {}; foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{tunnelState}->{oid}\.(.*)$/); my $instance = $1; @@ -133,6 +140,7 @@ sub manage_selection { status => $result->{tunnelState}, type => $result->{tunnelType} }; + $self->{global}->{total}++; } if (scalar(keys %{$self->{vpn}}) <= 0) { @@ -169,6 +177,11 @@ Can used special variables like: %{type}, %{status}, %{display} Checkpoint snmp can be buggy. Test that option if no response. +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'tunnels-total'. + =back =cut