centreon-plugins/centreon/common/airespace/snmp/mode/apusers.pm

325 lines
12 KiB
Perl
Raw Normal View History

2015-05-07 13:24:58 +02:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# 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.
#
2015-05-07 13:24:58 +02:00
package centreon::common::airespace::snmp::mode::apusers;
use base qw(centreon::plugins::templates::counter);
2015-05-07 13:24:58 +02:00
use strict;
use warnings;
2020-07-06 11:01:54 +02:00
sub prefix_global_output {
my ($self, %options) = @_;
return 'Users ';
}
sub prefix_ssid_output {
my ($self, %options) = @_;
return "SSID '" . $options{instance_value}->{display} . "' ";
}
sub prefix_ap_output {
my ($self, %options) = @_;
return "Access point '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
2020-07-06 11:01:54 +02:00
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 },
2016-05-24 14:41:09 +02:00
{ name => 'ssid', type => 1, cb_prefix_output => 'prefix_ssid_output', message_multiple => 'All users by SSID are ok' },
2020-07-06 11:01:54 +02:00
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All users by access point are ok' }
];
2020-07-06 11:01:54 +02:00
$self->{maps_counters}->{global} = [
2020-07-06 11:01:54 +02:00
{ label => 'total', nlabel => 'users.total.count', set => {
key_values => [ { name => 'total' } ],
2020-07-06 11:01:54 +02:00
output_template => 'total: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total', template => '%s', unit => 'users', min => 0 },
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-idle', nlabel => 'users.idle.count', set => {
key_values => [ { name => 'total_idle' } ],
2020-07-06 11:01:54 +02:00
output_template => 'idle: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_idle', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-aaapending', nlabel => 'users.aaapending.count', set => {
key_values => [ { name => 'total_aaapending' } ],
2020-07-06 11:01:54 +02:00
output_template => 'aaaPending: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_aaapending', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-authenticated', nlabel => 'users.authenticated.count', set => {
key_values => [ { name => 'total_authenticated' } ],
2020-07-06 11:01:54 +02:00
output_template => 'authenticated: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_authenticated', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-associated', nlabel => 'users.associated.count', set => {
2016-12-01 17:32:33 +01:00
key_values => [ { name => 'total_associated' } ],
2020-07-06 11:01:54 +02:00
output_template => 'associated: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_associated', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-disassociated', nlabel => 'users.disassociated.count', set => {
key_values => [ { name => 'total_disassociated' } ],
output_template => 'disassociated: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_disassociated', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-powersave', nlabel => 'users.powersave.count', set => {
key_values => [ { name => 'total_powersave' } ],
output_template => 'powersave: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_powersave', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-tobedeleted', nlabel => 'users.tobedeleted.count', set => {
key_values => [ { name => 'total_tobedeleted' } ],
2020-07-06 11:01:54 +02:00
output_template => 'to be deleted: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_tobedeleted', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-probing', nlabel => 'users.probing.count', set => {
key_values => [ { name => 'total_probing' } ],
2020-07-06 11:01:54 +02:00
output_template => 'probing: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_probing', template => '%s', unit => 'users', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-blacklisted', nlabel => 'users.blacklisted.count', set => {
key_values => [ { name => 'total_blacklisted' } ],
2020-07-06 11:01:54 +02:00
output_template => 'blacklisted: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_blacklisted', template => '%s', unit => 'users', min => 0 }
]
}
2020-07-06 11:01:54 +02:00
}
];
2016-01-12 15:10:39 +01:00
$self->{maps_counters}->{ssid} = [
2020-07-06 11:01:54 +02:00
{ label => 'ssid', nlabel => 'ssid.users.total.count', set => {
2016-01-12 15:10:39 +01:00
key_values => [ { name => 'total' }, { name => 'display' } ],
2020-07-06 11:01:54 +02:00
output_template => 'users: %s',
2016-01-12 15:10:39 +01:00
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'ssid', template => '%s', unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' },
]
2016-01-12 15:10:39 +01:00
}
2020-07-06 11:01:54 +02:00
}
2016-01-12 15:10:39 +01:00
];
2016-05-24 14:41:09 +02:00
$self->{maps_counters}->{ap} = [
2020-07-06 11:01:54 +02:00
{ label => 'ap', nlabel => 'accesspoint.users.total.count', set => {
2016-05-24 14:41:09 +02:00
key_values => [ { name => 'total' }, { name => 'display' } ],
2020-07-06 11:01:54 +02:00
output_template => 'users: %s',
2016-05-24 14:41:09 +02:00
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'ap', template => '%s', unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
2016-05-24 14:41:09 +02:00
}
2020-07-06 11:01:54 +02:00
}
2016-05-24 14:41:09 +02:00
];
2016-01-12 15:10:39 +01:00
}
2015-05-07 13:24:58 +02:00
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
2020-07-06 11:01:54 +02:00
2019-06-06 16:58:20 +02:00
$options{options}->add_options(arguments => {
2020-07-06 17:35:37 +02:00
'filter-ssid:s' => { name => 'filter_ssid' },
'filter-ap:s' => { name => 'filter_ap' },
'filter-group:s' => { name => 'filter_group' },
'ignore-ap-users' => { name => 'ignore_ap_users' }
2019-06-06 16:58:20 +02:00
});
2020-07-06 11:01:54 +02:00
2015-05-07 13:24:58 +02:00
return $self;
}
2020-07-06 11:01:54 +02:00
my $map_station_status = {
2015-05-07 13:24:58 +02:00
0 => 'idle',
1 => 'aaapending',
2 => 'authenticated',
3 => 'associated',
4 => 'powersave',
5 => 'disassociated',
6 => 'tobedeleted',
7 => 'probing',
2020-07-06 11:01:54 +02:00
8 => 'blacklisted'
};
2015-05-07 13:24:58 +02:00
my $mapping = {
2020-07-06 11:01:54 +02:00
ssid => { oid => '.1.3.6.1.4.1.14179.2.1.4.1.7' }, # bsnMobileStationSsid
status => { oid => '.1.3.6.1.4.1.14179.2.1.4.1.9', map => $map_station_status } # bsnMobileStationStatus
2015-05-07 13:24:58 +02:00
};
my $mapping2 = {
2020-07-06 11:01:54 +02:00
ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName
2016-01-12 15:10:39 +01:00
};
2015-05-07 13:24:58 +02:00
my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3';
2016-01-12 15:10:39 +01:00
my $oid_bsnDot11EssSsid = '.1.3.6.1.4.1.14179.2.1.1.1.2';
2016-05-24 14:41:09 +02:00
my $oid_bsnAPIfLoadNumOfClients = '.1.3.6.1.4.1.14179.2.2.13.1.4';
2015-05-07 13:24:58 +02:00
sub manage_selection {
my ($self, %options) = @_;
2020-07-06 11:01:54 +02:00
my $snmp_result = $options{snmp}->get_multiple_table(
oids => [
{ oid => $oid_agentInventoryMachineModel },
{ oid => $mapping->{status}->{oid} },
{ oid => $mapping->{ssid}->{oid} },
{ oid => $oid_bsnDot11EssSsid }
],
return_type => 1,
nothing_quit => 1
);
$self->{output}->output_add(
long_msg => "Model: " .
(defined($self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'}) ? $self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'} : 'unknown')
);
$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->{ssid} = {};
foreach my $oid (keys %$snmp_result) {
if ($oid =~ /^$oid_bsnDot11EssSsid/ && !defined($self->{ssid}->{ $snmp_result->{$oid} })) {
2020-07-17 09:44:07 +02:00
if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' &&
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_ssid}/) {
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid} . "': no matching filter.", debug => 1);
next;
}
2020-07-06 11:01:54 +02:00
$self->{ssid}->{ $snmp_result->{$oid} } = { display => $snmp_result->{$oid}, total => 0 };
2015-05-07 13:24:58 +02:00
next;
}
2020-07-06 11:01:54 +02:00
next if ($oid !~ /^$mapping->{ssid}->{oid}\.(.*)$/);
2016-01-12 15:10:39 +01:00
my $instance = $1;
2020-07-06 11:01:54 +02:00
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
2016-01-12 15:10:39 +01:00
if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' &&
2020-07-06 11:01:54 +02:00
$result->{ssid} !~ /$self->{option_results}->{filter_ssid}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{ssid} . "': no matching filter.", debug => 1);
2016-01-12 15:10:39 +01:00
next;
}
2020-07-06 11:01:54 +02:00
$self->{ssid}->{ $result->{ssid} } = { display => $result->{ssid}, total => 0 } if (!defined($self->{ssid}->{ $result->{ssid} }));
$self->{ssid}->{ $result->{ssid} }->{total}++;
$self->{global}->{total}++;
$self->{global}->{'total_' . $result->{status}}++;
2016-01-12 15:10:39 +01:00
}
2020-07-06 11:01:54 +02:00
2020-07-06 17:35:37 +02:00
return if (defined($self->{option_results}->{ignore_ap_users}));
2020-07-06 11:01:54 +02:00
my $request = [ { oid => $mapping2->{ap_name}->{oid} }, { oid => $oid_bsnAPIfLoadNumOfClients } ];
push @$request, { oid => $mapping2->{group_name}->{oid} }
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
$snmp_result = $options{snmp}->get_multiple_table(
oids => $request,
return_type => 1
);
2016-05-24 14:41:09 +02:00
# check by ap
$self->{ap} = {};
2020-07-06 11:01:54 +02:00
foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$mapping2->{ap_name}->{oid}\.(.*)/);
2016-05-24 14:41:09 +02:00
my $instance = $1;
2020-07-06 11:01:54 +02:00
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance);
2016-05-24 14:41:09 +02:00
if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' &&
2020-07-06 11:01:54 +02:00
$result->{ap_name} !~ /$self->{option_results}->{filter_ap}/) {
$self->{output}->output_add(long_msg => "skipping access point '" . $result->{ap_name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
$result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
$self->{output}->output_add(long_msg => "skipping access point '" . $result->{ap_name} . "': no matching filter.", debug => 1);
2016-05-24 14:41:09 +02:00
next;
}
2020-07-06 11:01:54 +02:00
foreach my $oid2 (keys %$snmp_result) {
2016-05-24 14:41:09 +02:00
next if ($oid2 !~ /^$oid_bsnAPIfLoadNumOfClients\.$instance\./);
2020-07-06 11:01:54 +02:00
$self->{ap}->{$instance} = { display => $result->{ap_name}, total => 0 } if (!defined($self->{ap}->{$instance}));
$self->{ap}->{$instance}->{total} += $snmp_result->{$oid2};
2016-05-24 14:41:09 +02:00
}
}
2015-05-07 13:24:58 +02:00
}
1;
__END__
=head1 MODE
2016-05-24 14:41:09 +02:00
Check users connected (total, by SSID, by AP).
2015-05-07 13:24:58 +02:00
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^total|total-idle$'
2020-07-06 11:01:54 +02:00
=item B<--filter-ssid>
2015-05-07 13:24:58 +02:00
2020-07-06 11:01:54 +02:00
Filter by SSID (can be a regexp).
2015-05-07 13:24:58 +02:00
2020-07-06 11:01:54 +02:00
=item B<--filter-ap>
2015-05-07 13:24:58 +02:00
2020-07-06 11:01:54 +02:00
Filter by access point name (can be a regexp).
2015-05-07 13:24:58 +02:00
2020-07-06 11:01:54 +02:00
=item B<--filter-group>
2015-05-07 13:24:58 +02:00
2020-07-06 11:01:54 +02:00
Filter by access point group (can be a regexp).
2015-05-07 13:24:58 +02:00
2020-07-06 17:35:37 +02:00
=item B<--ignore-ap-users>
Unmonitor users by access points.
2020-07-06 11:01:54 +02:00
=item B<--warning-*> B<--critical-*>
2016-05-24 14:41:09 +02:00
2020-07-06 11:01:54 +02:00
Thresholds.
Can be: 'total', 'total-idle', 'total-aaapending', 'total-authenticated',
'total-associated', 'total-powersave', 'total-disassociated', 'total-tobedeleted',
'total-probing', 'total-blacklisted', 'ssid', 'ap'.
2016-05-24 14:41:09 +02:00
2015-05-07 13:24:58 +02:00
=back
=cut