refacto airspace wlc ap-channel

This commit is contained in:
garnier-quentin 2020-07-06 11:35:57 +02:00
parent 7bbf9c3997
commit c9c88e6c3a
2 changed files with 209 additions and 131 deletions

View File

@ -25,38 +25,55 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub set_counters { sub ap_long_output {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ return "checking access point '" . $options{instance_value}->{display} . "'";
{ 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', template => '%s',
label_extra_instance => 1, instance_use => 'label_perfdata' },
],
}
},
{ label => 'interference-util', set => {
key_values => [ { name => 'interference_util' }, { name => 'label_perfdata' } ],
output_template => 'Interference Utilization : %s %%',
perfdatas => [
{ label => 'interference_util', value => 'interference_util', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'label_perfdata' },
],
}
},
];
} }
sub prefix_ap_output { sub prefix_ap_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "access point '" . $options{instance_value}->{display} . "' ";
}
sub prefix_channel_output {
my ($self, %options) = @_;
return "channel '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
return $options{instance_value}->{display} . " "; $self->{maps_counters_type} = [
{ 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 => 'channels', display_long => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'channels are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{channels} = [
{ label => 'interference-power', nlabel => 'accesspoint.interference.power.count', set => {
key_values => [ { name => 'interference_power' }, { name => 'display' } ],
output_template => 'interference power: %s',
perfdatas => [
{ label => 'interference_power', template => '%s',
label_extra_instance => 1 }
]
}
},
{ label => 'interference-util', nlabel => 'accesspoint.interference.utilization.percentage', set => {
key_values => [ { name => 'interference_util' }, { name => 'display' } ],
output_template => 'interference utilization: %s %%',
perfdatas => [
{ label => 'interference_util', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
}
];
} }
sub new { sub new {
@ -65,58 +82,80 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'filter-channel:s' => { name => 'filter_channel' }, 'filter-channel:s' => { name => 'filter_channel' },
'filter-group:s' => { name => 'filter_group' }
}); });
return $self; return $self;
} }
my $oid_bsnAPName = '.1.3.6.1.4.1.14179.2.2.1.1.3'; my $mapping = {
my $oid_bsnAPIfInterferencePower = '.1.3.6.1.4.1.14179.2.2.14.1.2'; ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
my $oid_bsnAPIfInterferenceUtilization = '.1.3.6.1.4.1.14179.2.2.14.1.22'; group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName
};
my $mapping2 = {
interference_power => { oid => '.1.3.6.1.4.1.14179.2.2.14.1.2' }, # bsnAPIfInterferencePower
interference_util => { oid => '.1.3.6.1.4.1.14179.2.2.14.1.22' } # bsnAPIfInterferenceUtilization
};
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{ap} = {}; my $request = [
$self->{results} = $options{snmp}->get_multiple_table( { oid => $mapping->{ap_name}->{oid} },
oids => [ { oid => $mapping2->{interference_power}->{oid} },
{ oid => $oid_bsnAPName }, { oid => $mapping2->{interference_util}->{oid} }
{ oid => $oid_bsnAPIfInterferencePower }, ];
{ oid => $oid_bsnAPIfInterferenceUtilization }, push @$request, { oid => $mapping->{group_name}->{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 nothing_quit => 1
); );
foreach my $oid (keys %{$self->{results}->{$oid_bsnAPName}}) {
$oid =~ /^$oid_bsnAPName\.(.*)$/; foreach (keys %$snmp_result) {
my $instance_mac = $1; next if (! /^$mapping->{ap_name}->{oid}\.(.*)/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$self->{results}->{$oid_bsnAPName}->{$oid} !~ /$self->{option_results}->{filter_name}/) { $result->{ap_name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "': no matching filter."); $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
next; next;
} }
my $instance_end; if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
foreach my $oid2 (keys %{$self->{results}->{$oid_bsnAPIfInterferencePower}}) { $result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
if ($oid2 =~ /^$oid_bsnAPIfInterferencePower\.$instance_mac\.(\d+)\.(\d+)$/) { $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
$instance_end = $1 . '.' . $2; next;
}
if (defined($self->{option_results}->{filter_channel}) && $self->{option_results}->{filter_channel} ne '' &&
$instance_end !~ /$self->{option_results}->{filter_channel}/) { $self->{ap}->{ $result->{ap_name} } = {
$self->{output}->output_add(long_msg => "Skipping channel '" . $instance_end . "': no matching filter."); display => $result->{ap_name},
next; channels => {}
} };
$self->{ap}->{$instance_mac . '.' . $instance_end} = { foreach my $oid (keys %$snmp_result) {
display => "AP '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "' Slot $1 Channel $2", next if ($oid !~ /^$mapping2->{interference_power}->{oid}\.$instance\.(\d+)\.(\d+)$/);
label_perfdata => $self->{results}->{$oid_bsnAPName}->{$oid} . "_$1_$2", my ($slot_id, $channel_id) = ($1, $2);
interference_power => $self->{results}->{$oid_bsnAPIfInterferencePower}->{$oid_bsnAPIfInterferencePower . '.' . $instance_mac . '.' . $instance_end},
interference_util => $self->{results}->{$oid_bsnAPIfInterferenceUtilization}->{$oid_bsnAPIfInterferenceUtilization . '.' . $instance_mac . '.' . $instance_end} my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance . '.' . $slot_id . '.' . $channel_id);
}; my $name = "slot$slot_id:channel$channel_id";
if (defined($self->{option_results}->{filter_channel}) && $self->{option_results}->{filter_channel} ne '' &&
$name !~ /$self->{option_results}->{filter_channel}/) {
$self->{output}->output_add(long_msg => "skipping channel '" . $name . "': no matching filter.", debug => 1);
next;
} }
$self->{ap}->{ $result->{ap_name} }->{channels}->{$name} = {
display => $name,
%$result2
};
} }
} }
if (scalar(keys %{$self->{ap}}) <= 0) { if (scalar(keys %{$self->{ap}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -138,23 +177,22 @@ Check AP Channel Interference.
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='interference-util' Example: --filter-counters='interference-util'
=item B<--warning-*>
Threshold warning.
Can be: 'interference-power', 'interference-util' (%).
=item B<--critical-*>
Threshold critical.
Can be: 'interference-power', 'interference-util' (%).
=item B<--filter-name> =item B<--filter-name>
Filter AP name (can be a regexp). Filter access point name (can be a regexp).
=item B<--filter-group>
Filter access point group (can be a regexp).
=item B<--filter-channel> =item B<--filter-channel>
Filter Channel (can be a regexp). Example: --filter-channel='0\.3' Filter channel (can be a regexp). Example: --filter-channel='slot0:channel3'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'interference-power', 'interference-util' (%).
=back =back

View File

@ -25,29 +25,45 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub set_counters { sub ap_long_output {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ return "checking access point '" . $options{instance_value}->{display} . "'";
{ 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', template => '%s',
unit => 'dBm', label_extra_instance => 1, instance_use => 'label_perfdata' },
],
}
},
];
} }
sub prefix_ap_output { sub prefix_ap_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "access point '" . $options{instance_value}->{display} . "' ";
}
sub prefix_channel_output {
my ($self, %options) = @_;
return "channel '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
return $options{instance_value}->{display} . " "; $self->{maps_counters_type} = [
{ 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 => 'channels', display_long => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'channels are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{channels} = [
{ label => 'noise-power', nlabel => 'accesspoint.noise.power.dbm', set => {
key_values => [ { name => 'noise_power' }, { name => 'display' } ],
output_template => 'noise power: %s dBm',
perfdatas => [
{ label => 'noise_power', template => '%s', unit => 'dBm', label_extra_instance => 1 }
]
}
}
];
} }
sub new { sub new {
@ -56,50 +72,75 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'filter-channel:s' => { name => 'filter_channel' }, 'filter-channel:s' => { name => 'filter_channel' },
'filter-group:s' => { name => 'filter_group' }
}); });
return $self; return $self;
} }
my $oid_bsnAPName = '.1.3.6.1.4.1.14179.2.2.1.1.3'; my $mapping = {
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
};
my $oid_bsnAPIfDBNoisePower = '.1.3.6.1.4.1.14179.2.2.15.1.21'; my $oid_bsnAPIfDBNoisePower = '.1.3.6.1.4.1.14179.2.2.15.1.21';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{ap} = {}; my $request = [
$self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_bsnAPName }, { oid => $oid_bsnAPIfDBNoisePower } ], { oid => $mapping->{ap_name}->{oid} },
nothing_quit => 1); { oid => $oid_bsnAPIfDBNoisePower }
foreach my $oid (keys %{$self->{results}->{$oid_bsnAPName}}) { ];
$oid =~ /^$oid_bsnAPName\.(.*)$/; push @$request, { oid => $mapping->{group_name}->{oid} }
my $instance_mac = $1; 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
);
foreach (keys %$snmp_result) {
next if (! /^$mapping->{ap_name}->{oid}\.(.*)/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$self->{results}->{$oid_bsnAPName}->{$oid} !~ /$self->{option_results}->{filter_name}/) { $result->{ap_name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "': no matching filter."); $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
next; next;
} }
my $instance_end; if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
foreach my $oid2 (keys %{$self->{results}->{$oid_bsnAPIfDBNoisePower}}) { $result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
if ($oid2 =~ /^$oid_bsnAPIfDBNoisePower\.$instance_mac\.(\d+)\.(\d+)$/) { $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
$instance_end = $1 . '.' . $2; next;
}
if (defined($self->{option_results}->{filter_channel}) && $self->{option_results}->{filter_channel} ne '' &&
$instance_end !~ /$self->{option_results}->{filter_channel}/) { $self->{ap}->{ $result->{ap_name} } = {
$self->{output}->output_add(long_msg => "Skipping channel '" . $instance_end . "': no matching filter."); display => $result->{ap_name},
next; channels => {}
} };
$self->{ap}->{$instance_mac . '.' . $instance_end} = { foreach my $oid (keys %$snmp_result) {
display => "AP '" . $self->{results}->{$oid_bsnAPName}->{$oid} . "' Slot $1 Channel $2", next if ($oid !~ /^$oid_bsnAPIfDBNoisePower\.$instance\.(\d+)\.(\d+)$/);
label_perfdata => $self->{results}->{$oid_bsnAPName}->{$oid} . "_$1_$2", my ($slot_id, $channel_id) = ($1, $2);
noise_power => $self->{results}->{$oid_bsnAPIfDBNoisePower}->{$oid_bsnAPIfDBNoisePower . '.' . $instance_mac . '.' . $instance_end}
}; my $name = "slot$slot_id:channel$channel_id";
if (defined($self->{option_results}->{filter_channel}) && $self->{option_results}->{filter_channel} ne '' &&
$name !~ /$self->{option_results}->{filter_channel}/) {
$self->{output}->output_add(long_msg => "skipping channel '" . $name . "': no matching filter.", debug => 1);
next;
} }
$self->{ap}->{ $result->{ap_name} }->{channels}->{$name} = {
display => $name,
noise_power => $snmp_result->{$oid}
};
} }
} }
if (scalar(keys %{$self->{ap}}) <= 0) { if (scalar(keys %{$self->{ap}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -116,23 +157,22 @@ Check AP Channel Noise.
=over 8 =over 8
=item B<--warning-*>
Threshold warning.
Can be: 'noise-power' (dBm).
=item B<--critical-*>
Threshold critical.
Can be: 'noise-power' (dBm).
=item B<--filter-name> =item B<--filter-name>
Filter AP name (can be a regexp). Filter access point name (can be a regexp).
=item B<--filter-group>
Filter access point group (can be a regexp).
=item B<--filter-channel> =item B<--filter-channel>
Filter Channel (can be a regexp). Example: --filter-channel='0\.3' Filter channel (can be a regexp). Example: --filter-channel='slot0:channel3'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'noise-power' (dBm).
=back =back