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

314 lines
11 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::apstatus;
use base qw(centreon::plugins::templates::counter);
2015-05-07 13:24:58 +02:00
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
2015-05-07 13:24:58 +02:00
sub custom_status_output {
my ($self, %options) = @_;
2020-07-06 11:01:54 +02:00
my $msg = $self->{result_values}->{admstatus} eq 'disabled' ? 'is disabled' : 'status: ' . $self->{result_values}->{opstatus};
2015-05-07 13:24:58 +02:00
return $msg;
}
2020-07-06 11:01:54 +02:00
sub skip_global {
2015-05-07 13:24:58 +02:00
my ($self, %options) = @_;
2020-07-06 11:01:54 +02:00
scalar(keys %{$self->{ap}}) == 1 ? return(1) : return(0);
}
2020-07-06 17:27:00 +02:00
sub prefix_global_output {
my ($self, %options) = @_;
return 'Access points ';
}
sub ap_long_output {
my ($self, %options) = @_;
return "checking access point '" . $options{instance_value}->{display} . "'";
}
2020-07-06 11:01:54 +02:00
sub prefix_ap_output {
my ($self, %options) = @_;
2020-07-06 17:27:00 +02:00
return "access point '" . $options{instance_value}->{display} . "' ";
2020-07-06 11:01:54 +02:00
}
2020-07-06 17:27:00 +02:00
sub prefix_interface_output {
2020-07-06 11:01:54 +02:00
my ($self, %options) = @_;
2020-07-06 17:27:00 +02:00
return "radio interface '" . $options{instance_value}->{display} . "' ";
2015-05-07 13:24:58 +02:00
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
2020-07-06 11:01:54 +02:00
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', cb_init => 'skip_global', },
2020-07-06 17:27:00 +02:00
{ name => 'ap', type => 3, cb_prefix_output => 'prefix_ap_output', cb_long_output => 'ap_long_output', indent_long_output => ' ', message_multiple => 'All access points are ok',
group => [
{ name => 'ap_global', type => 0 },
{ name => 'interfaces', type => 1, display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'radio interfaces are ok', skipped_code => { -10 => 1 } }
]
}
];
2020-07-06 17:27:00 +02:00
$self->{maps_counters}->{global} = [
2020-07-06 11:01:54 +02:00
{ label => 'total', nlabel => 'accesspoints.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', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-associated', nlabel => 'accesspoints.associated.count', set => {
key_values => [ { name => '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', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-disassociating', nlabel => 'accesspoints.disassociating.count', set => {
key_values => [ { name => 'disassociating' } ],
2020-07-06 11:01:54 +02:00
output_template => 'disassociating: %s',
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_disassociating', template => '%s', min => 0 }
]
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-enabled', nlabel => 'accesspoints.enabled.count', set => {
2017-06-26 13:45:26 +02:00
key_values => [ { name => 'enable' } ],
2020-07-06 11:01:54 +02:00
output_template => 'enabled: %s',
2017-06-26 13:45:26 +02:00
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_enabled', template => '%s', min => 0 }
]
2017-06-26 13:45:26 +02:00
}
},
2020-07-06 11:01:54 +02:00
{ label => 'total-disabled', nlabel => 'accesspoints.disabled.count', set => {
2017-06-26 13:45:26 +02:00
key_values => [ { name => 'disable' } ],
2020-07-06 11:01:54 +02:00
output_template => 'disabled: %s',
2017-06-26 13:45:26 +02:00
perfdatas => [
2020-07-06 11:01:54 +02:00
{ label => 'total_disabled', template => '%s', min => 0 }
]
2017-06-26 13:45:26 +02:00
}
2020-07-06 11:01:54 +02:00
}
];
2020-07-06 17:27:00 +02:00
$self->{maps_counters}->{ap_global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
2020-07-06 11:01:54 +02:00
closure_custom_threshold_check => \&catalog_status_threshold
}
2020-07-06 11:01:54 +02:00
}
];
2020-07-06 17:27:00 +02:00
$self->{maps_counters}->{interfaces} = [
{ label => 'radio-interface-channels-utilization', nlabel => 'accesspoint.radio.interface.channels.utilization.percentage', set => {
key_values => [ { name => 'channels_util' } ],
output_template => 'channels utilization: %s %%',
perfdatas => [
{ label => 'radio_interface_channels_utilization', template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
}
];
}
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
$options{options}->add_options(arguments => {
2020-07-06 17:27:00 +02:00
'filter-name:s' => { name => 'filter_name' },
'filter-group:s' => { name => 'filter_group' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/' },
'add-radio-interfaces' => { name => 'add_radio_interfaces' }
2020-07-06 11:01:54 +02:00
});
2015-05-07 13:24:58 +02:00
return $self;
}
sub check_options {
my ($self, %options) = @_;
2016-01-29 15:48:41 +01:00
$self->SUPER::check_options(%options);
2015-12-17 16:12:08 +01:00
$self->change_macros(macros => ['warning_status', 'critical_status']);
2015-05-07 13:24:58 +02:00
}
2020-07-06 11:01:54 +02:00
my $map_admin_status = {
2015-05-07 13:24:58 +02:00
1 => 'enable',
2020-07-06 11:01:54 +02:00
2 => 'disable'
};
my $map_operation_status = {
2015-05-07 13:24:58 +02:00
1 => 'associated',
2 => 'disassociating',
2020-07-06 11:01:54 +02:00
3 => 'downloading'
};
2015-05-07 13:24:58 +02:00
my $mapping = {
2020-07-06 11:01:54 +02:00
bsnAPName => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' },
bsnAPGroupVlanName => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' }
2015-05-07 13:24:58 +02:00
};
my $mapping2 = {
2020-07-06 11:01:54 +02:00
bsnAPOperationStatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.6', map => $map_operation_status },
bsnAPAdminStatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.37', map => $map_admin_status }
2015-05-07 13:24:58 +02:00
};
my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3';
2020-07-06 17:27:00 +02:00
my $oid_bsnAPIfLoadChannelUtilization = '.1.3.6.1.4.1.14179.2.2.13.1.3';
2015-05-07 13:24:58 +02:00
sub manage_selection {
my ($self, %options) = @_;
$self->{ap} = {};
2017-06-26 13:45:26 +02:00
$self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0, enable => 0, disable => 0 };
2020-07-06 11:01:54 +02:00
my $request = [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{bsnAPName}->{oid} } ];
push @$request, { oid => $mapping->{bsnAPGroupVlanName}->{oid} }
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
my $snmp_result = $options{snmp}->get_multiple_table(
oids => $request,
return_type => 1,
nothing_quit => 1
);
$self->{output}->output_add(
long_msg => 'Model: ' .
(defined($snmp_result->{$oid_agentInventoryMachineModel . '.0'}) ? $snmp_result->{$oid_agentInventoryMachineModel . '.0'} : 'unknown')
);
foreach (keys %$snmp_result) {
next if (! /^$mapping->{bsnAPName}->{oid}\.(.*)/);
2015-05-07 13:24:58 +02: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);
2015-05-07 13:24:58 +02:00
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{bsnAPName} !~ /$self->{option_results}->{filter_name}/) {
2020-07-06 11:01:54 +02:00
$self->{output}->output_add(long_msg => "skipping '" . $result->{bsnAPName} . "'.", debug => 1);
2015-05-07 13:24:58 +02:00
next;
}
2020-07-06 11:01:54 +02:00
if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
$result->{bsnAPGroupVlanName} !~ /$self->{option_results}->{filter_group}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{bsnAPName} . "'.", debug => 1);
next;
}
2020-07-06 17:27:00 +02:00
$self->{ap}->{ $result->{bsnAPName} } = {
instance => $instance,
display => $result->{bsnAPName},
ap_global => { display => $result->{bsnAPName} },
interfaces => {}
2020-07-06 11:01:54 +02:00
};
2015-05-07 13:24:58 +02:00
}
2020-07-06 11:01:54 +02:00
if (scalar(keys %{$self->{ap}}) <= 0) {
$self->{output}->output_add(long_msg => 'no AP associated (can be: slave wireless controller or your filter)');
2020-07-06 11:01:54 +02:00
return ;
}
$options{snmp}->load(
oids => [ map($_->{oid}, values(%$mapping2)) ],
2020-07-06 17:27:00 +02:00
instances => [ map($_->{instance}, values %{$self->{ap}}) ],
2020-07-06 11:01:54 +02:00
instance_regexp => '^(.*)$'
);
$snmp_result = $options{snmp}->get_leef();
2020-07-06 17:27:00 +02:00
my $snmp_result_radio;
$snmp_result_radio = $options{snmp}->get_table(oid => $oid_bsnAPIfLoadChannelUtilization)
if (defined($self->{option_results}->{add_radio_interfaces}));
2020-07-06 11:01:54 +02:00
foreach (keys %{$self->{ap}}) {
2020-07-06 17:27:00 +02:00
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $self->{ap}->{$_}->{instance});
2020-07-06 11:01:54 +02:00
$self->{global}->{total}++;
$self->{global}->{$result->{bsnAPOperationStatus}}++;
$self->{global}->{$result->{bsnAPAdminStatus}}++;
2020-07-06 17:27:00 +02:00
$self->{ap}->{$_}->{ap_global}->{opstatus} = $result->{bsnAPOperationStatus};
$self->{ap}->{$_}->{ap_global}->{admstatus} = $result->{bsnAPAdminStatus};
next if (!defined($self->{option_results}->{add_radio_interfaces}));
foreach my $oid (keys %$snmp_result_radio) {
next if ($oid !~ /^$oid_bsnAPIfLoadChannelUtilization\.$self->{ap}->{$_}->{instance}\.(\d+)/);
$self->{ap}->{$_}->{interfaces}->{$1} = {
display => $1,
channels_util => $snmp_result_radio->{$oid}
};
}
2015-05-07 13:24:58 +02:00
}
}
1;
__END__
=head1 MODE
Check AP status.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^total-disassociating|total-associated$'
2015-05-07 13:24:58 +02:00
=item B<--filter-name>
2020-07-06 11:01:54 +02:00
Filter access point name (can be a regexp).
=item B<--filter-group>
Filter access point group (can be a regexp).
2015-05-07 13:24:58 +02:00
2020-07-06 17:27:00 +02:00
=item B<--add-radio-interfaces>
Monitor radio interfaces channels utilization.
2015-12-17 16:12:08 +01:00
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{admstatus}, %{opstatus}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/').
Can used special variables like: %{admstatus}, %{opstatus}, %{display}
2020-07-06 11:01:54 +02:00
=item B<--warning-*> B<--critical-*>
2015-05-07 13:24:58 +02:00
2020-07-06 17:27:00 +02:00
Thresholds.
Can be: 'total', 'total-associated', 'total-disassociating', 'total-enabled',
'total-disabled', 'radio-interface-channels-utilization' (%).
2015-05-07 13:24:58 +02:00
=back
=cut