From 41f2a564900a009cae05547515348d4ad5fb8420 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 2 Oct 2020 14:21:15 +0200 Subject: [PATCH] fix #2178 --- .../network/paloalto/ssh/mode/ha.pm | 52 +++++-------------- .../network/paloalto/ssh/mode/interfaces.pm | 28 +++------- .../network/paloalto/ssh/mode/ipsec.pm | 19 +++++-- .../network/paloalto/ssh/mode/licenses.pm | 15 ++---- .../network/paloalto/ssh/mode/system.pm | 36 ++++++------- 5 files changed, 53 insertions(+), 97 deletions(-) diff --git a/centreon-plugins/network/paloalto/ssh/mode/ha.pm b/centreon-plugins/network/paloalto/ssh/mode/ha.pm index b8ab2ac25..f7274328d 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/ha.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/ha.pm @@ -25,27 +25,25 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_sync_status_output { my ($self, %options) = @_; - my $msg = sprintf( + return sprintf( 'sync status: %s [enabled: %s]', $self->{result_values}->{status}, $self->{result_values}->{enabled} ); - return $msg; } sub custom_member_status_output { my ($self, %options) = @_; - my $msg = sprintf( + return sprintf( 'state: %s', $self->{result_values}->{state} ); - return $msg; } sub custom_member_status_calc { @@ -79,42 +77,40 @@ sub set_counters { { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All members are ok', group => [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, - { name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; $self->{maps_counters}->{sync} = [ - { label => 'sync-status', threshold => 0, set => { + { label => 'sync-status', type => 2, critical_default => '%{enabled} eq "yes" and %{status} ne "synchronized"', set => { key_values => [ { name => 'enabled' }, { name => 'status'} ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_sync_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{global} = [ - { label => 'member-status', threshold => 0, set => { + { label => 'member-status', type => 2, critical_default => '%{state} ne %{stateLast}', set => { key_values => [ { name => 'state' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_member_status_calc'), closure_custom_output => $self->can('custom_member_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; $self->{maps_counters}->{link} = [ - { label => 'link-status', threshold => 0, set => { + { label => 'link-status', type => 2, critical_default => '%{status} ne "up"', set => { key_values => [ { name => 'status' }, { name => 'display' } ], - closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_link_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng } - }, + } ]; } @@ -142,33 +138,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, - 'warning-member-status:s' => { name => 'warning_member_status', default => '' }, - 'critical-member-status:s' => { name => 'critical_member_status', default => '%{state} ne %{stateLast}' }, - 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, - 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, - 'critical-link-status:s' => { name => 'critical_link_status', default => '%{status} ne "up"' }, - 'unknown-sync-status:s' => { name => 'unknown_sync_status', default => '' }, - 'warning-sync-status:s' => { name => 'warning_sync_status', default => '' }, - 'critical-sync-status:s' => { name => 'critical_sync_status', default => '%{enabled} eq "yes" and %{status} ne "synchronized"' }, }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros( - macros => [ - 'unknown_sync_status', 'warning_sync_status', 'critical_sync_status', - 'unknown_member_status', 'warning_member_status', 'critical_member_status', - 'unknown_link_status', 'warning_link_status', 'critical_link_status' - ] - ); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm b/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm index ccb778615..f0fb82d06 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm @@ -25,17 +25,16 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf( + return sprintf( 'state: %s [type: %s]', $self->{result_values}->{state}, $self->{result_values}->{type} ); - return $msg; } sub set_counters { @@ -51,22 +50,21 @@ sub set_counters { key_values => [ { name => 'total' } ], output_template => 'total interfaces: %s', perfdatas => [ - { value => 'total', template => '%s', min => 0 } + { template => '%s', min => 0 } ] } }, ]; $self->{maps_counters}->{interface} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{state} ne "up"', set => { key_values => [ { name => 'state' }, { name => 'type' }, { name => 'ha_state' }, { name => 'display' } ], - 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_ng } } ]; @@ -84,26 +82,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "up"' } + 'filter-name:s' => { name => 'filter_name' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros( - macros => [ - 'unknown_status', 'warning_status', 'critical_status' - ] - ); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm index f7f18742f..6cfe2056d 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm @@ -83,6 +83,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } }); return $self; @@ -96,7 +97,13 @@ sub manage_selection { $self->{global} = { total_ipsec => 0 }; $self->{tunnels} = {}; foreach (@{$result->{entry}}) { - $self->{tunnels}->{$_->{gwid}} = { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{tunnels}->{ $_->{gwid} } = { display => $_->{name}, ike_phase1_state => defined($_->{created}) && $_->{created} ne '' ? 'up' : 'down', monitor_status => 'unknown', # could be 'up', 'down', 'off' @@ -106,6 +113,8 @@ sub manage_selection { $self->{global}->{total_ipsec}++; } + return if ($self->{global}->{total_ipsec} == 0); + $result = $options{custom}->execute_command(command => 'show vpn ipsec-sa', ForceArray => ['entry']); foreach (@{$result->{entries}->{entry}}) { if (defined($self->{tunnels}->{$_->{gwid}})) { @@ -118,8 +127,8 @@ sub manage_selection { next if (!defined($self->{tunnels}->{$gwid}->{tid})); foreach (@{$result->{IPSec}->{entry}}) { next if ($self->{tunnels}->{$gwid}->{tid} ne $_->{id}); - $self->{tunnels}->{$_->{gwid}}->{state} = $_->{state}; - $self->{tunnels}->{$_->{gwid}}->{monitor_status} = $_->{mon}; + $self->{tunnels}->{ $_->{gwid} }->{state} = $_->{state}; + $self->{tunnels}->{ $_->{gwid} }->{monitor_status} = $_->{mon}; } } } @@ -134,6 +143,10 @@ Check ipsec tunnels. =over 8 +=item B<--filter-name> + +Filter tunnels by name (can be a regexp). + =item B<--unknown-status> Set unknown threshold for status. diff --git a/centreon-plugins/network/paloalto/ssh/mode/licenses.pm b/centreon-plugins/network/paloalto/ssh/mode/licenses.pm index e4a2837e6..cfeed4cdc 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/licenses.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/licenses.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use DateTime; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -63,12 +63,12 @@ sub set_counters { ]; $self->{maps_counters}->{features} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{expired} eq "yes"', set => { key_values => [ { name => 'feature' }, { name => 'expired' }, { name => 'expiry_date' }, { name => 'expiry_seconds' } ], closure_custom_calc => $self->can('custom_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_ng } }, ]; @@ -86,20 +86,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{expired} eq "yes"' }, }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/network/paloalto/ssh/mode/system.pm b/centreon-plugins/network/paloalto/ssh/mode/system.pm index c56426064..a4c115ce9 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/system.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/system.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use DateTime; use centreon::plugins::misc; use Digest::MD5 qw(md5_hex); @@ -32,8 +32,7 @@ use Digest::MD5 qw(md5_hex); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'system operational mode: ' . $self->{result_values}->{oper_mode}; - return $msg; + return 'system operational mode: ' . $self->{result_values}->{oper_mode}; } sub custom_av_output { @@ -64,28 +63,27 @@ sub set_counters { ]; $self->{maps_counters}->{system} = [ - { label => 'status', threshold => 0, set => { + { label => 'status', type => 2, critical_default => '%{oper_mode} !~ /normal/i', set => { key_values => [ { name => 'oper_mode' } ], - 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_ng } }, { label => 'av-update', nlabel => 'system.antivirus.lastupdate.time.seconds', set => { key_values => [ { name => 'av_lastupdate_time' }, { name => 'av_version' } ], closure_custom_output => $self->can('custom_av_output'), perfdatas => [ - { value => 'av_lastupdate_time', template => '%d', min => 0, unit => 's' } - ], + { template => '%d', min => 0, unit => 's' } + ] } }, { label => 'threat-update', nlabel => 'system.threat.lastupdate.time.seconds', set => { key_values => [ { name => 'threat_lastupdate_time' }, { name => 'threat_version' } ], closure_custom_output => $self->can('custom_threat_output'), perfdatas => [ - { value => 'threat_lastupdate_time', template => '%d', min => 0, unit => 's' } - ], + { template => '%d', min => 0, unit => 's' } + ] } }, { label => 'sessions-traffic', nlabel => 'system.sessions.traffic.count', set => { @@ -93,19 +91,18 @@ sub set_counters { output_template => 'session traffic: %s %s/s', output_change_bytes => 2, perfdatas => [ - { value => 'throughput', template => '%s', - unit => 'b/s', min => 0 }, - ], + { template => '%s', unit => 'b/s', min => 0 } + ] } }, { label => 'sessions-total-active', nlabel => 'system.sessions.total.active.count', display_ok => 0, set => { key_values => [ { name => 'active_sessions' } ], output_template => 'total active sessions: %s', perfdatas => [ - { value => 'active_sessions', template => '%s', min => 0 }, - ], + { template => '%s', min => 0 } + ] } - }, + } ]; } @@ -114,10 +111,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{oper_mode} !~ /normal/i' }, - 'timezone:s' => { name => 'timezone' } + $options{options}->add_options(arguments => { + 'timezone:s' => { name => 'timezone' } }); return $self; @@ -127,7 +122,6 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_status', 'critical_status']); $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); }