Debian Codegraph @

src/centreon/common/airespace/snmp/mode/apstatus.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::apstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = $self->{result_values}->{admstatus} eq 'disable' ? 'is disabled' : ('status: ' . $self->{result_values}->{opstatus});
33 return $msg;
34 }
35
36 sub custom_radio_channel_util_calc {
37 my ($self, %options) = @_;
38
39 return -10 if ($options{new_datas}->{$self->{instance} . '_admstatus'} eq 'disable');
40 $self->{result_values}->{channels_util} = $options{new_datas}->{$self->{instance} . '_channels_util'};
41 return 0;
42 }
43
44 sub prefix_global_output {
45 my ($self, %options) = @_;
46
47 return 'Access points ';
48 }
49
50 sub ap_long_output {
51 my ($self, %options) = @_;
52
53 return "checking access point '" . $options{instance_value}->{display} . "'";
54 }
55
56 sub prefix_ap_output {
57 my ($self, %options) = @_;
58
59 return "access point '" . $options{instance_value}->{display} . "' ";
60 }
61
62 sub prefix_interface_output {
63 my ($self, %options) = @_;
64
65 return "radio interface '" . $options{instance_value}->{display} . "' ";
66 }
67
68 sub set_counters {
69 my ($self, %options) = @_;
70
71 $self->{maps_counters_type} = [
72 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
73 { 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',
74 group => [
75 { name => 'ap_global', type => 0 },
76 { name => 'interfaces', type => 1, display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'radio interfaces are ok', skipped_code => { -10 => 1 } }
77 ]
78 }
79 ];
80
81 $self->{maps_counters}->{global} = [
82 { label => 'total', nlabel => 'accesspoints.total.count', set => {
83 key_values => [ { name => 'total' } ],
84 output_template => 'total: %s',
85 perfdatas => [
86 { label => 'total', template => '%s', min => 0 }
87 ]
88 }
89 },
90 { label => 'total-associated', nlabel => 'accesspoints.associated.count', set => {
91 key_values => [ { name => 'associated' } ],
92 output_template => 'associated: %s',
93 perfdatas => [
94 { label => 'total_associated', template => '%s', min => 0 }
95 ]
96 }
97 },
98 { label => 'total-disassociating', nlabel => 'accesspoints.disassociating.count', set => {
99 key_values => [ { name => 'disassociating' } ],
100 output_template => 'disassociating: %s',
101 perfdatas => [
102 { label => 'total_disassociating', template => '%s', min => 0 }
103 ]
104 }
105 },
106 { label => 'total-downloading', nlabel => 'accesspoints.downloading.count', display_ok => 0, set => {
107 key_values => [ { name => 'downloading' } ],
108 output_template => 'downloading: %s',
109 perfdatas => [
110 { label => 'total_downloading', template => '%s', min => 0 }
111 ]
112 }
113 },
114 { label => 'total-enabled', nlabel => 'accesspoints.enabled.count', set => {
115 key_values => [ { name => 'enable' } ],
116 output_template => 'enabled: %s',
117 perfdatas => [
118 { label => 'total_enabled', template => '%s', min => 0 }
119 ]
120 }
121 },
122 { label => 'total-disabled', nlabel => 'accesspoints.disabled.count', set => {
123 key_values => [ { name => 'disable' } ],
124 output_template => 'disabled: %s',
125 perfdatas => [
126 { label => 'total_disabled', template => '%s', min => 0 }
127 ]
128 }
129 }
130 ];
131
132 $self->{maps_counters}->{ap_global} = [
133 { label => 'status', type => 2, critical_default => '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/', set => {
134 key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ],
135 closure_custom_output => $self->can('custom_status_output'),
136 closure_custom_perfdata => sub { return 0; },
137 closure_custom_threshold_check => \&catalog_status_threshold_ng
138 }
139 }
140 ];
141
142 $self->{maps_counters}->{interfaces} = [
143 { label => 'radio-status', type => 2, critical_default => '%{admstatus} eq "enable" and %{opstatus} eq "down"', set => {
144 key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ],
145 closure_custom_output => $self->can('custom_status_output'),
146 closure_custom_perfdata => sub { return 0; },
147 closure_custom_threshold_check => \&catalog_status_threshold_ng
148 }
149 },
150 { label => 'radio-interface-channels-utilization', nlabel => 'accesspoint.radio.interface.channels.utilization.percentage', set => {
151 key_values => [ { name => 'channels_util' }, { name => 'admstatus' } ],
152 closure_custom_calc => $self->can('custom_radio_channel_util_calc'),
153 output_template => 'channels utilization: %s %%',
154 perfdatas => [
155 { label => 'radio_interface_channels_utilization', template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
156 ]
157 }
158 }
159 ];
160 }
161
162 sub new {
163 my ($class, %options) = @_;
164 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
165 bless $self, $class;
166
167 $options{options}->add_options(arguments => {
168 'filter-name:s' => { name => 'filter_name' },
169 'filter-group:s' => { name => 'filter_group' },
170 'add-radio-interfaces' => { name => 'add_radio_interfaces' }
171 });
172
173 return $self;
174 }
175
176 my $map_admin_status = {
177 1 => 'enable',
178 2 => 'disable'
179 };
180 my $map_operation_status = {
181 1 => 'associated',
182 2 => 'disassociating',
183 3 => 'downloading'
184 };
185 my $map_radio_operation_status = {
186 1 => 'down',
187 2 => 'up'
188 };
189
190 my $mapping = {
191 ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
192 group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName
193 };
194 my $mapping2 = {
195 opstatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.6', map => $map_operation_status }, # bsnAPOperationStatus
196 admstatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.37', map => $map_admin_status } # bsnAPAdminStatus
197 };
198 my $mapping3 = {
199 opstatus => { oid => '.1.3.6.1.4.1.14179.2.2.2.1.12', map => $map_radio_operation_status }, # bsnAPIfOperStatus
200 admstatus => { oid => '.1.3.6.1.4.1.14179.2.2.2.1.34', map => $map_admin_status }, # bsnAPIfAdminStatus
201 channels_util => { oid => '.1.3.6.1.4.1.14179.2.2.13.1.3' } # bsnAPIfLoadChannelUtilization
202 };
203 my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3';
204
205 sub manage_selection {
206 my ($self, %options) = @_;
207
208 $self->{ap} = {};
209 $self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0, enable => 0, disable => 0 };
210
211 my $request = [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{ap_name}->{oid} } ];
212 push @$request, { oid => $mapping->{group_name}->{oid} }
213 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
214
215 my $snmp_result = $options{snmp}->get_multiple_table(
216 oids => $request,
217 return_type => 1,
218 nothing_quit => 1
219 );
220
221 $self->{output}->output_add(
222 long_msg => 'Model: ' .
223 (defined($snmp_result->{$oid_agentInventoryMachineModel . '.0'}) ? $snmp_result->{$oid_agentInventoryMachineModel . '.0'} : 'unknown')
224 );
225
226 foreach (keys %$snmp_result) {
227 next if (! /^$mapping->{ap_name}->{oid}\.(.*)/);
228 my $instance = $1;
229
230 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
231 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
232 $result->{ap_name} !~ /$self->{option_results}->{filter_name}/) {
233 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
234 next;
235 }
236 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
237 $result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
238 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
239 next;
240 }
241
242 $self->{ap}->{ $result->{ap_name} } = {
243 instance => $instance,
244 display => $result->{ap_name},
245 ap_global => { display => $result->{ap_name} },
246 interfaces => {}
247 };
248 }
249
250 if (scalar(keys %{$self->{ap}}) <= 0) {
251 $self->{output}->output_add(long_msg => 'no AP associated (can be: slave wireless controller or your filter)');
252 return ;
253 }
254
255 $options{snmp}->load(
256 oids => [ map($_->{oid}, values(%$mapping2)) ],
257 instances => [ map($_->{instance}, values %{$self->{ap}}) ],
258 instance_regexp => '^(.*)$'
259 );
260 $snmp_result = $options{snmp}->get_leef();
261
262 my $snmp_result_radio;
263 $snmp_result_radio = $options{snmp}->get_multiple_table(oids => [map({ oid => $_->{oid} }, values(%$mapping3))], return_type => 1)
264 if (defined($self->{option_results}->{add_radio_interfaces}));
265
266 foreach (keys %{$self->{ap}}) {
267 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $self->{ap}->{$_}->{instance});
268
269 $self->{global}->{total}++;
270 $self->{global}->{ $result->{opstatus} }++;
271 $self->{global}->{ $result->{admstatus} }++;
272 $self->{ap}->{$_}->{ap_global}->{opstatus} = $result->{opstatus};
273 $self->{ap}->{$_}->{ap_global}->{admstatus} = $result->{admstatus};
274
275 next if (!defined($self->{option_results}->{add_radio_interfaces}));
276
277 foreach my $oid (keys %$snmp_result_radio) {
278 next if ($oid !~ /^$mapping3->{admstatus}->{oid}\.$self->{ap}->{$_}->{instance}\.(\d+)/);
279 my $result_radio = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result_radio, instance => $self->{ap}->{$_}->{instance} . '.' . $1);
280 $self->{ap}->{$_}->{interfaces}->{$1} = {
281 display => $1,
282 %$result_radio
283 };
284 }
285 }
286 }
287
288 1;
289
290 __END__
291
292 =head1 MODE
293
294 Check AP status.
295
296 =over 8
297
298 =item B<--filter-counters>
299
300 Only display some counters (regexp can be used).
301 Example: --filter-counters='^total-disassociating|total-associated$'
302
303 =item B<--filter-name>
304
305 Filter access point name (can be a regexp).
306
307 =item B<--filter-group>
308
309 Filter access point group (can be a regexp).
310
311 =item B<--add-radio-interfaces>
312
313 Monitor radio interfaces channels utilization.
314
315 =item B<--warning-status>
316
317 Define the conditions to match for the status to be WARNING.
318 You can use the following variables: %{admstatus}, %{opstatus}, %{display}
319
320 =item B<--critical-status>
321
322 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/').
323 You can use the following variables: %{admstatus}, %{opstatus}, %{display}
324
325 =item B<--warning-radio-status>
326
327 Define the conditions to match for the status to be WARNING.
328 You can use the following variables: %{admstatus}, %{opstatus}, %{display}
329
330 =item B<--critical-radio-status>
331
332 Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "enable" and %{opstatus} eq "down"').
333 You can use the following variables: %{admstatus}, %{opstatus}, %{display}
334
335 =item B<--warning-*> B<--critical-*>
336
337 Thresholds.
338 Can be: 'total', 'total-associated', 'total-disassociating', 'total-downloading',
339 'total-enabled', 'total-disabled', 'radio-interface-channels-utilization' (%).
340
341 =back
342
343 =cut