Debian Codegraph @

src/centreon/common/airespace/snmp/mode/apchannelinterference.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package centreon::common::airespace::snmp::mode::apchannelinterference;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub ap_long_output {
29 my ($self, %options) = @_;
30
31 return "checking access point '" . $options{instance_value}->{display} . "'";
32 }
33
34 sub prefix_ap_output {
35 my ($self, %options) = @_;
36
37 return "access point '" . $options{instance_value}->{display} . "' ";
38 }
39
40 sub prefix_channel_output {
41 my ($self, %options) = @_;
42
43 return "channel '" . $options{instance_value}->{display} . "' ";
44 }
45
46 sub set_counters {
47 my ($self, %options) = @_;
48
49 $self->{maps_counters_type} = [
50 { 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',
51 group => [
52 { name => 'channels', display_long => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'channels are ok', type => 1, skipped_code => { -10 => 1 } }
53 ]
54 }
55 ];
56
57 $self->{maps_counters}->{channels} = [
58 { label => 'interference-power', nlabel => 'accesspoint.interference.power.count', set => {
59 key_values => [ { name => 'interference_power' }, { name => 'display' } ],
60 output_template => 'interference power: %s',
61 perfdatas => [
62 { label => 'interference_power', template => '%s',
63 label_extra_instance => 1 }
64 ]
65 }
66 },
67 { label => 'interference-util', nlabel => 'accesspoint.interference.utilization.percentage', set => {
68 key_values => [ { name => 'interference_util' }, { name => 'display' } ],
69 output_template => 'interference utilization: %s %%',
70 perfdatas => [
71 { label => 'interference_util', template => '%s',
72 unit => '%', min => 0, max => 100, label_extra_instance => 1 }
73 ]
74 }
75 }
76 ];
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments => {
85 'filter-name:s' => { name => 'filter_name' },
86 'filter-channel:s' => { name => 'filter_channel' },
87 'filter-group:s' => { name => 'filter_group' }
88 });
89
90 return $self;
91 }
92
93 my $mapping = {
94 ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
95 group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName
96 };
97 my $mapping2 = {
98 interference_power => { oid => '.1.3.6.1.4.1.14179.2.2.14.1.2' }, # bsnAPIfInterferencePower
99 interference_util => { oid => '.1.3.6.1.4.1.14179.2.2.14.1.22' } # bsnAPIfInterferenceUtilization
100 };
101
102 sub manage_selection {
103 my ($self, %options) = @_;
104
105 my $request = [
106 { oid => $mapping->{ap_name}->{oid} },
107 { oid => $mapping2->{interference_power}->{oid} },
108 { oid => $mapping2->{interference_util}->{oid} }
109 ];
110 push @$request, { oid => $mapping->{group_name}->{oid} }
111 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
112
113 my $snmp_result = $options{snmp}->get_multiple_table(
114 oids => $request,
115 return_type => 1,
116 nothing_quit => 1
117 );
118
119 foreach (keys %$snmp_result) {
120 next if (! /^$mapping->{ap_name}->{oid}\.(.*)/);
121 my $instance = $1;
122
123 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
124 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
125 $result->{ap_name} !~ /$self->{option_results}->{filter_name}/) {
126 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
127 next;
128 }
129 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
130 $result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
131 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
132 next;
133 }
134
135 $self->{ap}->{ $result->{ap_name} } = {
136 display => $result->{ap_name},
137 channels => {}
138 };
139
140 foreach my $oid (keys %$snmp_result) {
141 next if ($oid !~ /^$mapping2->{interference_power}->{oid}\.$instance\.(\d+)\.(\d+)$/);
142 my ($slot_id, $channel_id) = ($1, $2);
143
144 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance . '.' . $slot_id . '.' . $channel_id);
145 my $name = "slot$slot_id:channel$channel_id";
146 if (defined($self->{option_results}->{filter_channel}) && $self->{option_results}->{filter_channel} ne '' &&
147 $name !~ /$self->{option_results}->{filter_channel}/) {
148 $self->{output}->output_add(long_msg => "skipping channel '" . $name . "': no matching filter.", debug => 1);
149 next;
150 }
151
152 $self->{ap}->{ $result->{ap_name} }->{channels}->{$name} = {
153 display => $name,
154 %$result2
155 };
156 }
157 }
158
159 if (scalar(keys %{$self->{ap}}) <= 0) {
160 $self->{output}->add_option_msg(short_msg => "No entry found.");
161 $self->{output}->option_exit();
162 }
163 }
164
165 1;
166
167 __END__
168
169 =head1 MODE
170
171 Check AP Channel Interference.
172
173 =over 8
174
175 =item B<--filter-counters>
176
177 Only display some counters (regexp can be used).
178 Example: --filter-counters='interference-util'
179
180 =item B<--filter-name>
181
182 Filter access point name (can be a regexp).
183
184 =item B<--filter-group>
185
186 Filter access point group (can be a regexp).
187
188 =item B<--filter-channel>
189
190 Filter channel (can be a regexp). Example: --filter-channel='slot0:channel3'
191
192 =item B<--warning-*> B<--critical-*>
193
194 Thresholds.
195 Can be: 'interference-power', 'interference-util' (%).
196
197 =back
198
199 =cut