From 42bf729648ceaae1fdec366d5d393bb5e318e187 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 Jan 2016 16:14:44 +0100 Subject: [PATCH] + work on migrating airespace mode with template counter --- .../snmp/mode/apchannelinterference.pm | 160 +++------- .../airespace/snmp/mode/apchannelnoise.pm | 140 ++------- .../common/airespace/snmp/mode/apstatus.pm | 2 +- .../common/airespace/snmp/mode/apusers.pm | 275 +++++++----------- .../centreon/plugins/templates/counter.pm | 14 +- 5 files changed, 190 insertions(+), 401 deletions(-) diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm index 87f7cd341..eb0e9827d 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelinterference.pm @@ -20,38 +20,44 @@ package centreon::common::airespace::snmp::mode::apchannelinterference; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; -my $maps_counters = { - '000_interference-power' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'interference_power' }, { name => 'label_perfdata' }, - ], - output_template => 'Interference Power : %s', - perfdatas => [ - { label => 'interference_power', value => 'interference_power_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'label_perfdata_absolute' }, - ], - } - }, - '001_interference-util' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'interference_util' }, { name => 'label_perfdata' }, - ], - output_template => 'Interference Utilization : %s %%', - perfdatas => [ - { label => 'interference_util', value => 'interference_util_absolute', template => '%s', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'label_perfdata_absolute' }, - ], - } - }, -}; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All AP interference statistics are ok' }, + ]; + $self->{maps_counters}->{ap} = [ + { label => 'interference-power', set => { + key_values => [ { name => 'interference_power' }, { name => 'label_perfdata' } ], + output_template => 'Interference Power : %s', + perfdatas => [ + { label => 'interference_power', value => 'interference_power_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'label_perfdata_absolute' }, + ], + } + }, + { label => 'interference-util', set => { + key_values => [ { name => 'interference_util' }, { name => 'label_perfdata' } ], + output_template => 'Interference Utilization : %s %%', + perfdatas => [ + { label => 'interference_util', value => 'interference_util_absolute', template => '%s', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'label_perfdata_absolute' }, + ], + } + }, + ]; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return $options{instance_value}->{display} . " "; +} sub new { my ($class, %options) = @_; @@ -64,97 +70,10 @@ sub new { "filter-name:s" => { name => 'filter_name' }, "filter-channel:s" => { name => 'filter_channel' }, }); - - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{ap_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All AP interference statistics are ok'); - } - - foreach my $id ($self->{snmp}->oid_lex_sort(keys %{$self->{ap_selected}})) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{ap_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => $self->{ap_selected}->{$id}->{display} . " $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - my $oid_bsnAPName = '.1.3.6.1.4.1.14179.2.2.1.1.3'; my $oid_bsnAPIfInterferencePower = '.1.3.6.1.4.1.14179.2.2.14.1.2'; my $oid_bsnAPIfInterferenceUtilization = '.1.3.6.1.4.1.14179.2.2.14.1.22'; @@ -162,7 +81,7 @@ my $oid_bsnAPIfInterferenceUtilization = '.1.3.6.1.4.1.14179.2.2.14.1.22'; sub manage_selection { my ($self, %options) = @_; - $self->{ap_selected} = {}; + $self->{ap} = {}; $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName }, { oid => $oid_bsnAPIfInterferencePower }, { oid => $oid_bsnAPIfInterferenceUtilization }, @@ -187,7 +106,7 @@ sub manage_selection { next; } - $self->{ap_selected}->{$instance_mac . '.' . $instance_end} = { + $self->{ap}->{$instance_mac . '.' . $instance_end} = { display => "AP '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "' Slot $1 Channel $2", label_perfdata => $self->{results}->{$oid_bsnAPName}->{$oid} . "_$1_$2", interference_power => $self->{results}->{$oid_bsnAPIfInterferencePower}->{$oid_bsnAPIfInterferencePower . '.' . $instance_mac . '.' . $instance_end}, @@ -197,7 +116,7 @@ sub manage_selection { } } - if (scalar(keys %{$self->{ap_selected}}) <= 0) { + if (scalar(keys %{$self->{ap}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } @@ -213,6 +132,11 @@ Check AP Channel Interference. =over 8 +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example to check SSL connections only : --filter-counters='interference-util' + =item B<--warning-*> Threshold warning. diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm index 4accb7bc1..2dbce5b9d 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apchannelnoise.pm @@ -20,26 +20,35 @@ package centreon::common::airespace::snmp::mode::apchannelnoise; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; -my $maps_counters = { - '000_noise-power' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'noise_power' }, { name => 'label_perfdata' } - ], - output_template => 'Noise Power : %s dBm', - perfdatas => [ - { label => 'noise_power', value => 'noise_power_absolute', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'label_perfdata_absolute' }, - ], - } - }, -}; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All AP noise statistics are ok' }, + ]; + $self->{maps_counters}->{ap} = [ + { label => 'noise-power', set => { + key_values => [ { name => 'noise_power' }, { name => 'label_perfdata' } ], + output_template => 'Noise Power : %s dBm', + perfdatas => [ + { label => 'noise_power', value => 'noise_power_absolute', template => '%s', + unit => 'dBm', label_extra_instance => 1, instance_use => 'label_perfdata_absolute' }, + ], + } + }, + ]; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return $options{instance_value}->{display} . " "; +} sub new { my ($class, %options) = @_; @@ -53,107 +62,18 @@ sub new { "filter-channel:s" => { name => 'filter_channel' }, }); - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{ap_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All AP noise statistics are ok'); - } - - foreach my $id ($self->{snmp}->oid_lex_sort(keys %{$self->{ap_selected}})) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{ap_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => $self->{ap_selected}->{$id}->{display} . " $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => $self->{ap_selected}->{$id}->{display} . " $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - my $oid_bsnAPName = '.1.3.6.1.4.1.14179.2.2.1.1.3'; my $oid_bsnAPIfDBNoisePower = '.1.3.6.1.4.1.14179.2.2.15.1.21'; sub manage_selection { my ($self, %options) = @_; - $self->{ap_selected} = {}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName }, - { oid => $oid_bsnAPIfDBNoisePower }, - ], - nothing_quit => 1); + $self->{ap} = {}; + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName }, { oid => $oid_bsnAPIfDBNoisePower } ], + nothing_quit => 1); foreach my $oid (keys %{$self->{results}->{$oid_bsnAPName}}) { $oid =~ /^$oid_bsnAPName\.(.*)$/; my $instance_mac = $1; @@ -173,7 +93,7 @@ sub manage_selection { next; } - $self->{ap_selected}->{$instance_mac . '.' . $instance_end} = { + $self->{ap}->{$instance_mac . '.' . $instance_end} = { display => "AP '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "' Slot $1 Channel $2", label_perfdata => $self->{results}->{$oid_bsnAPName}->{$oid} . "_$1_$2", noise_power => $self->{results}->{$oid_bsnAPIfDBNoisePower}->{$oid_bsnAPIfDBNoisePower . '.' . $instance_mac . '.' . $instance_end} @@ -182,7 +102,7 @@ sub manage_selection { } } - if (scalar(keys %{$self->{ap_selected}}) <= 0) { + if (scalar(keys %{$self->{ap}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm index 77e956f72..0e213e440 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm @@ -149,7 +149,7 @@ sub check_options { sub skip_global { my ($self, %options) = @_; - scalar(keys %{$self->{ap}}) > 0 ? return(1) : return(0); + scalar(keys %{$self->{ap}}) > 1 ? return(0) : return(1); } sub prefix_ap_output { diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm index 63834926b..67931e44c 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm @@ -20,105 +20,110 @@ package centreon::common::airespace::snmp::mode::apusers; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; -my $maps_counters = { - '000_total' => { set => { - key_values => [ { name => 'total' } ], - output_template => 'Total Users : %s', - perfdatas => [ - { label => 'total', value => 'total_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '001_total-idle' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ { name => 'total_idle' } ], - output_template => 'Total Idle Users : %s', - perfdatas => [ - { label => 'total_idle', value => 'total_idle_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '002_total-aaapending' => { set => { - key_values => [ { name => 'total_aaapending' } ], - output_template => 'Total AaaPending Users : %s', - perfdatas => [ - { label => 'total_aaapending', value => 'total_aaapending_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '003_total-authenticated' => { set => { - key_values => [ { name => 'total_authenticated' } ], - output_template => 'Total Authenticated Users : %s', - perfdatas => [ - { label => 'total_authenticated', value => 'total_authenticated_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '004_total-associated' => { set => { - key_values => [ { name => 'total_associated' } ], - output_template => 'Total Associated Users : %s', - perfdatas => [ - { label => 'total_associated', value => 'total_associated_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '005_total-powersave' => { set => { - key_values => [ { name => 'total_powersave' } ], - output_template => 'Total Powersave Users : %s', - perfdatas => [ - { label => 'total_powersave', value => 'total_powersave_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '006_total-disassociated' => { set => { - key_values => [ { name => 'total_disassociated' } ], - output_template => 'Total Disassociated Users : %s', - perfdatas => [ - { label => 'total_disassociated', value => 'total_disassociated_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '007_total-tobedeleted' => { set => { - key_values => [ { name => 'total_tobedeleted' } ], - output_template => 'Total ToBeDeleted Users : %s', - perfdatas => [ - { label => 'total_tobedeleted', value => 'total_tobedeleted_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '008_total-probing' => { set => { - key_values => [ { name => 'total_probing' } ], - output_template => 'Total Probing Users : %s', - perfdatas => [ - { label => 'total_probing', value => 'total_probing_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, - '009_total-blacklisted' => { set => { - key_values => [ { name => 'total_blacklisted' } ], - output_template => 'Total Blacklisted Users : %s', - perfdatas => [ - { label => 'total_blacklisted', value => 'total_blacklisted_absolute', template => '%s', - unit => 'users', min => 0 }, - ], - } - }, -}; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total Users : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-idle', set => { + key_values => [ { name => 'total_idle' } ], + output_template => 'Total Idle Users : %s', + perfdatas => [ + { label => 'total_idle', value => 'total_idle_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-aaapending', set => { + key_values => [ { name => 'total_aaapending' } ], + output_template => 'Total AaaPending Users : %s', + perfdatas => [ + { label => 'total_aaapending', value => 'total_aaapending_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-authenticated', set => { + key_values => [ { name => 'total_authenticated' } ], + output_template => 'Total Authenticated Users : %s', + perfdatas => [ + { label => 'total_authenticated', value => 'total_authenticated_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-associated', set => { + key_values => [ { name => 'total_aaapending' } ], + output_template => 'Total AaaPending Users : %s', + perfdatas => [ + { label => 'total_aaapending', value => 'total_aaapending_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-powersave', set => { + key_values => [ { name => 'total_powersave' } ], + output_template => 'Total Powersave Users : %s', + perfdatas => [ + { label => 'total_powersave', value => 'total_powersave_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-disassociated', set => { + key_values => [ { name => 'total_disassociated' } ], + output_template => 'Total Disassociated Users : %s', + perfdatas => [ + { label => 'total_disassociated', value => 'total_disassociated_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-tobedeleted', set => { + key_values => [ { name => 'total_tobedeleted' } ], + output_template => 'Total ToBeDeleted Users : %s', + perfdatas => [ + { label => 'total_tobedeleted', value => 'total_tobedeleted_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-probing', set => { + key_values => [ { name => 'total_probing' } ], + output_template => 'Total Probing Users : %s', + perfdatas => [ + { label => 'total_probing', value => 'total_probing_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + { label => 'total-blacklisted', set => { + key_values => [ { name => 'total_blacklisted' } ], + output_template => 'Total Blacklisted Users : %s', + perfdatas => [ + { label => 'total_blacklisted', value => 'total_blacklisted_absolute', template => '%s', + unit => 'users', min => 0 }, + ], + } + }, + ]; +} sub new { my ($class, %options) = @_; @@ -130,79 +135,10 @@ sub new { { "filter-ssid:s" => { name => 'filter_ssid' }, }); - - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => 'global'); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{global}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(); - } - - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "$short_msg" - ); - } else { - $self->{output}->output_add(short_msg => "$long_msg"); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - my %map_station_status = ( 0 => 'idle', 1 => 'aaapending', @@ -229,7 +165,7 @@ sub manage_selection { $self->{global} = { total => 0, total_idle => 0, total_aaapending => 0, total_authenticated => 0, total_associated => 0, total_powersave => 0, total_disassociated => 0, total_tobedeleted => 0, total_probing => 0, total_blacklisted => 0}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel }, + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{bsnMobileStationStatus}->{oid} }, { oid => $mapping2->{bsnMobileStationSsid}->{oid} }, ], @@ -238,8 +174,8 @@ sub manage_selection { foreach my $oid (keys %{$self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }}) { $oid =~ /^$mapping->{bsnMobileStationStatus}->{oid}\.(.*)$/; my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }, instance => $instance); - my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{ $mapping2->{bsnMobileStationSsid}->{oid} }, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }, instance => $instance); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{ $mapping2->{bsnMobileStationSsid}->{oid} }, instance => $instance); if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && $result2->{bsnMobileStationSsid} !~ /$self->{option_results}->{filter_ssid}/) { $self->{output}->output_add(long_msg => "Skipping '" . $result2->{bsnMobileStationSsid} . "': no matching filter."); @@ -260,6 +196,11 @@ Check total users connected and status on AP. =over 8 +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example to check SSL connections only : --filter-counters='^total|total-idle$' + =item B<--warning-*> Threshold warning. diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index e1b8d6ad0..b3ca7b0d5 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -169,7 +169,7 @@ sub run_global { my $prefix_output; $prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}) if (defined($options{config}->{cb_prefix_output})); - $prefix_output = '' if (defined($prefix_output)); + $prefix_output = '' if (!defined($prefix_output)); my $exit = $self->{output}->get_most_critical(status => [ @exits ]); if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { @@ -198,11 +198,15 @@ sub run_instances { my $message_separator = defined($options{config}->{message_separator}) ? $options{config}->{message_separator}: ', '; - foreach my $id (sort keys %{$options{config}->{name}}) { + foreach my $id (sort keys %{$self->{$options{config}->{name}}}) { my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); my @exits = (); foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) { my $obj = $_->{obj}; + + next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_counters}/); + $obj->set(instance => $id); my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, @@ -231,7 +235,7 @@ sub run_instances { my $prefix_output; $prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$id}) if (defined($options{config}->{cb_prefix_output})); - $prefix_output = '' if (defined($prefix_output)); + $prefix_output = '' if (!defined($prefix_output)); $self->{output}->output_add(long_msg => "${prefix_output}$long_msg"); my $exit = $self->{output}->get_most_critical(status => [ @exits ]); @@ -260,9 +264,9 @@ sub run { } foreach my $entry (@{$self->{maps_counters_type}}) { - if ($_->{type} == 0) { + if ($entry->{type} == 0) { $self->run_global(config => $entry); - } elsif ($_->{type} == 1) { + } elsif ($entry->{type} == 1) { $self->run_instances(config => $entry); } }