From 6f3ca369b63a88c2b8e4095177e7530c1412724c Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 20 Jul 2016 15:00:06 +0200 Subject: [PATCH 1/5] + add aerohive plugin https://github.com/centreon/centreon-plugins/issues/445 --- network/aerohive/snmp/plugin.pm | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 network/aerohive/snmp/plugin.pm diff --git a/network/aerohive/snmp/plugin.pm b/network/aerohive/snmp/plugin.pm new file mode 100644 index 000000000..02a736b20 --- /dev/null +++ b/network/aerohive/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::aerohive::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'connected-users' => 'network::aerohive::snmp::mode::connectedusers', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check aerohive equipment in SNMP + +=cut From dbce4168f6c12bb490882a6615d33d337183f02b Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 20 Jul 2016 15:01:29 +0200 Subject: [PATCH 2/5] + add connectedusers mode Fix https://github.com/centreon/centreon-plugins/issues/445 --- network/aerohive/snmp/mode/connectedusers.pm | 144 +++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 network/aerohive/snmp/mode/connectedusers.pm diff --git a/network/aerohive/snmp/mode/connectedusers.pm b/network/aerohive/snmp/mode/connectedusers.pm new file mode 100644 index 000000000..e7fc608b9 --- /dev/null +++ b/network/aerohive/snmp/mode/connectedusers.pm @@ -0,0 +1,144 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::aerohive::snmp::mode::connectedusers; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'ssid', type => 1, cb_prefix_output => 'prefix_ssid_output', message_multiple => 'All users by SSID are ok' }, + ]; + $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 }, + ], + } + }, + ]; + $self->{maps_counters}->{ssid} = [ + { label => 'ssid', set => { + key_values => [ { name => 'total' }, { name => 'display' } ], + output_template => 'users : %s', + perfdatas => [ + { label => 'ssid', value => 'total_absolute', template => '%s', + unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_ssid_output { + my ($self, %options) = @_; + + return "SSID '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-ssid:s" => { name => 'filter_ssid' }, + }); + + return $self; +} + +my $oid_ahXIfEntry = '.1.3.6.1.4.1.26928.1.1.1.2.1.1.1'; +my $oid_ahSSIDNAME = '.1.3.6.1.4.1.26928.1.1.1.2.1.1.1.2'; +my $oid_ahClientSSID = '.1.3.6.1.4.1.26928.1.1.1.2.1.2.1.10'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { total => 0 }; + $self->{ssid} = {}; + + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_ahXIfEntry }, + { oid => $oid_ahClientSSID }, + ], + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}->{ $oid_ahXIfEntry }}) { + next if $oid !~ /^$oid_ahSSIDNAME\.(.*)$/; + my $ssid = $self->{results}->{ $oid_ahXIfEntry }->{$oid}; + if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && + $ssid !~ /$self->{option_results}->{filter_ssid}/) { + $self->{output}->output_add(long_msg => "skipping ssid " . $ssid . " : no matching filter.", debug => 1); + next; + } + $self->{ssid}->{$ssid} = { display => $ssid, total => 0 } if (!defined($self->{ssid}->{$ssid})); + } + + foreach my $oid (keys %{$self->{results}->{ $oid_ahClientSSID }}) { + $self->{global}->{total}++; + my $ssid = $self->{results}->{ $oid_ahClientSSID }->{$oid}; + $self->{ssid}->{$ssid}->{total}++; + } + +} + +1; + +__END__ + +=head1 MODE + +Check number of connected users (total and by SSID). + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='ssid$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'ssid' + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'ssid' + +=item B<--filter-ssid> + +Filter by SSID (can be a regexp). + +=back + +=cut From 0ca496409b693f730f4753be3927458c8652567d Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 20 Jul 2016 15:48:50 +0200 Subject: [PATCH 3/5] + minor optimizations ++ enhance error management when filter by SSID ++ reduce snmp query scope --- network/aerohive/snmp/mode/connectedusers.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/network/aerohive/snmp/mode/connectedusers.pm b/network/aerohive/snmp/mode/connectedusers.pm index e7fc608b9..75ce6686e 100644 --- a/network/aerohive/snmp/mode/connectedusers.pm +++ b/network/aerohive/snmp/mode/connectedusers.pm @@ -76,7 +76,6 @@ sub new { return $self; } -my $oid_ahXIfEntry = '.1.3.6.1.4.1.26928.1.1.1.2.1.1.1'; my $oid_ahSSIDNAME = '.1.3.6.1.4.1.26928.1.1.1.2.1.1.1.2'; my $oid_ahClientSSID = '.1.3.6.1.4.1.26928.1.1.1.2.1.2.1.10'; @@ -86,13 +85,12 @@ sub manage_selection { $self->{global} = { total => 0 }; $self->{ssid} = {}; - $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_ahXIfEntry }, + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_ahSSIDNAME }, { oid => $oid_ahClientSSID }, ], nothing_quit => 1); foreach my $oid (keys %{$self->{results}->{ $oid_ahXIfEntry }}) { - next if $oid !~ /^$oid_ahSSIDNAME\.(.*)$/; my $ssid = $self->{results}->{ $oid_ahXIfEntry }->{$oid}; if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && $ssid !~ /$self->{option_results}->{filter_ssid}/) { @@ -105,7 +103,7 @@ sub manage_selection { foreach my $oid (keys %{$self->{results}->{ $oid_ahClientSSID }}) { $self->{global}->{total}++; my $ssid = $self->{results}->{ $oid_ahClientSSID }->{$oid}; - $self->{ssid}->{$ssid}->{total}++; + $self->{ssid}->{$ssid}->{total}++ if defined($self->{ssid}->{$ssid}); } } From cd0574864469b05d05a9320e4b0c624f26ccc8bc Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 20 Jul 2016 16:03:14 +0200 Subject: [PATCH 4/5] + syntax guidelines --- network/aerohive/snmp/mode/connectedusers.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/aerohive/snmp/mode/connectedusers.pm b/network/aerohive/snmp/mode/connectedusers.pm index 75ce6686e..d2f7ff181 100644 --- a/network/aerohive/snmp/mode/connectedusers.pm +++ b/network/aerohive/snmp/mode/connectedusers.pm @@ -103,7 +103,7 @@ sub manage_selection { foreach my $oid (keys %{$self->{results}->{ $oid_ahClientSSID }}) { $self->{global}->{total}++; my $ssid = $self->{results}->{ $oid_ahClientSSID }->{$oid}; - $self->{ssid}->{$ssid}->{total}++ if defined($self->{ssid}->{$ssid}); + $self->{ssid}->{$ssid}->{total}++ if (defined($self->{ssid}->{$ssid})); } } From 6214ed39cf30f0649c175f60c655b281ff2c085d Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 20 Jul 2016 16:06:45 +0200 Subject: [PATCH 5/5] + fix error on ssid in foreach --- network/aerohive/snmp/mode/connectedusers.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/aerohive/snmp/mode/connectedusers.pm b/network/aerohive/snmp/mode/connectedusers.pm index d2f7ff181..e4839dd42 100644 --- a/network/aerohive/snmp/mode/connectedusers.pm +++ b/network/aerohive/snmp/mode/connectedusers.pm @@ -90,8 +90,8 @@ sub manage_selection { ], nothing_quit => 1); - foreach my $oid (keys %{$self->{results}->{ $oid_ahXIfEntry }}) { - my $ssid = $self->{results}->{ $oid_ahXIfEntry }->{$oid}; + foreach my $oid (keys %{$self->{results}->{ $oid_ahSSIDNAME }}) { + my $ssid = $self->{results}->{ $oid_ahSSIDNAME }->{$oid}; if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && $ssid !~ /$self->{option_results}->{filter_ssid}/) { $self->{output}->output_add(long_msg => "skipping ssid " . $ssid . " : no matching filter.", debug => 1);