Debian Codegraph @

src/network/huawei/wlc/snmp/mode/aphealth.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 network::huawei::wlc::snmp::mode::aphealth;
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 = 'data link state: ' . $self->{result_values}->{datalinkstate} . ', power-supply: ' . $self->{result_values}->{powersupply};
33 return $msg;
34 }
35
36 sub prefix_global_output {
37 my ($self, %options) = @_;
38
39 return 'Access points ';
40 }
41
42 sub ap_long_output {
43 my ($self, %options) = @_;
44
45 return "checking access point '" . $options{instance_value}->{display} . "'";
46 }
47
48 sub prefix_ap_output {
49 my ($self, %options) = @_;
50
51 return "access point '" . $options{instance_value}->{display} . "' ";
52 }
53
54 sub custom_uptime_output {
55 my ($self, %options) = @_;
56
57 return sprintf(
58 'access point %s online time is: %s', $self->{result_values}->{display},
59 centreon::plugins::misc::change_seconds(value => $self->{result_values}->{onlinetime}, start => 'd')
60 );
61 }
62
63 sub set_counters {
64 my ($self, %options) = @_;
65
66 $self->{maps_counters_type} = [
67 { name => 'ap',
68 type => 3,
69 cb_prefix_output => 'prefix_ap_output',
70 cb_long_output => 'ap_long_output',
71 indent_long_output => ' ',
72 message_multiple => 'All access points are ok',
73 group => [
74 { name => 'health', type => 0 }
75 ]
76 }
77 ];
78
79 $self->{maps_counters}->{health} = [
80 {
81 label => 'status',
82 type => 2,
83 critical_default => '%{powersupply} =~ /insufficient|limited/ || %{datalinkstate} !~ /run/',
84 warning_default => '%{powersupply} eq "limited"',
85 set =>
86 {
87 key_values =>
88 [ { name => 'powersupply' }, { name => 'display' }, { name => 'datalinkstate' } ],
89 closure_custom_output =>
90 $self->can('custom_status_output'),
91 closure_custom_perfdata =>
92 sub {return 0;},
93 closure_custom_threshold_check =>
94 \&catalog_status_threshold_ng
95 }
96 },
97 { label => 'temperature', nlabel => 'ap.temperature.celsius', set => {
98 key_values => [ { name => 'temperature' }, { name => 'display' } ],
99 output_template => 'access point temperature: %.2f C',
100 perfdatas => [
101 { template => '%.2f', unit => 'C', label_extra_instance => 1, instance_use => 'display' }
102 ]
103 }
104 },
105 { label => 'onlinetime', nlabel => 'ap.online.time', set => {
106 key_values => [ { name => 'onlinetime' }, { name => 'display' } ],
107 closure_custom_output => $self->can('custom_uptime_output'),
108 perfdatas => [
109 { template => '%d', unit => '', label_extra_instance => 1, instance_use => 'display' }
110 ]
111 }
112 },
113 { label => 'bootcount-total', nlabel => 'ap.boot.total.count', set => {
114 key_values => [ { name => 'bootcount_total' }, { name => 'display' } ],
115 output_template => 'access point bootcount total: %d',
116 perfdatas => [
117 { template => '%d', unit => '', label_extra_instance => 1, instance_use => 'display' }
118 ]
119 }
120 },
121 { label => 'memory', nlabel => 'ap.memory.used.percentage', set => {
122 key_values => [ { name => 'memory' }, { name => 'display' } ],
123 output_template => 'access point memory: %.2f %%',
124 perfdatas => [
125 { template => '%.2f', unit => '%', label_extra_instance => 1, instance_use => 'display' }
126 ]
127 }
128 },
129 { label => 'cpu', nlabel => 'ap.cpu.used.percentage', set => {
130 key_values => [ { name => 'cpu' }, { name => 'display' } ],
131 output_template => 'access point cpu: %.2f%%',
132 perfdatas => [
133 { template => '%.2f', unit => '%', label_extra_instance => 1, instance_use => 'display' }
134 ]
135 }
136 },
137 { label => 'up-port-speed', nlabel => 'ap.up.port.bitspersecond', set => {
138 key_values => [ { name => 'up_port_speed' }, { name => 'display' } ],
139 output_template => 'access point up-Port speed: %s b/s',
140 perfdatas => [
141 { template => '%s', unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
142 ]
143 }
144 },
145 { label => 'up-port-packet-err', nlabel => 'ap.up.port.package.error.percentage', set => {
146 key_values => [ { name => 'up_port_per' }, { name => 'display' } ],
147 output_template => 'access point up-Port packet errors: %.2f%%',
148 perfdatas => [
149 { template => '%.2f', unit => '', label_extra_instance => 1, instance_use => 'display' }
150 ]
151 }
152 },
153 { label => 'online-user-num', nlabel => 'ap.online.user.count', set => {
154 key_values => [ { name => 'online_user_num' }, { name => 'display' } ],
155 output_template => 'access online user nums: %d',
156 perfdatas => [
157 { template => '%d', unit => '', label_extra_instance => 1, instance_use => 'display' }
158 ]
159 }
160 }
161 ];
162 }
163
164 sub new {
165 my ($class, %options) = @_;
166 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
167 bless $self, $class;
168
169 $options{options}->add_options(arguments => {
170 "filter-name:s" => { name => 'filter_name' },
171 "filter-address:s" => { name => 'filter_address' },
172 "filter-group:s" => { name => 'filter_group' }
173 });
174
175 return $self;
176 }
177
178 my $map_power_supply_state = {
179 1 => 'normal',
180 2 => 'insufficient',
181 3 => 'limited',
182 4 => 'invalid'
183 };
184
185 my $map_data_link_state = {
186 1 => 'down',
187 2 => 'run',
188 3 => 'noneed'
189 };
190
191 my $mapping = {
192 name => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.4' },# hwWlanApName
193 address => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.13' }# hwWlanApIpAddress
194 };
195
196 my $mapping_stat = {
197 runtime => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.18' },# hwWlanApRunTime
198 group => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.5' },# hwWlanApGroup
199 temperature => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.43' },# hwWlanApTemperature
200 onlinetime => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.21' },# hwWlanApOnlineTime
201 bootcount_total => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.33' },# hwWlanApBootCountTotal
202 memory => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.40' },# hwWlanApMemoryUseRate
203 cpu => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.41' },# hwWlanApCPUUseRate
204 up_port_speed => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.54' },# hwWlanApUpPortSpeed
205 up_port_per => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.55' },# hwWlanAPUpPortPER
206 online_user_num => { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.44' },# hwWlanApOnlineUserNum
207 powersupply =>
208 { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.80', map => $map_power_supply_state },# hwWlanAPPowerSupplyState
209 datalinkstate =>
210 { oid => '.1.3.6.1.4.1.2011.6.139.13.3.3.1.81', map => $map_data_link_state }# hwWlanApDataLinkState
211 };
212
213 sub manage_selection {
214 my ($self, %options) = @_;
215
216 $self->{ap} = {};
217
218 my $request = [ { oid => $mapping->{name}->{oid} } ];
219 push @$request, { oid => $mapping->{group}->{oid} }
220 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
221
222 push @$request, { oid => $mapping->{address}->{oid} }
223 if (defined($self->{option_results}->{filter_address}) && $self->{option_results}->{filter_address} ne '');
224
225 my $snmp_result = $options{snmp}->get_multiple_table(
226 oids => $request,
227 return_type => 1,
228 nothing_quit => 1
229 );
230
231 foreach (sort keys %$snmp_result) {
232 next if (!/^$mapping->{name}->{oid}\.(.*)/);
233 my $instance = $1;
234
235 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
236 if (!defined($result->{name}) || $result->{name} eq '') {
237 $self->{output}->output_add(long_msg =>
238 "skipping WLC '$instance': cannot get a name. please set it.",
239 debug => 1);
240 next;
241 }
242
243 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
244 $result->{name} !~ /$self->{option_results}->{filter_name}/) {
245 $self->{output}->output_add(long_msg =>
246 "skipping '" . $result->{name} . "': no matching name filter.",
247 debug => 1);
248 next;
249 }
250
251 if (defined($self->{option_results}->{filter_address}) && $self->{option_results}->{filter_address} ne '' &&
252 $result->{address} !~ /$self->{option_results}->{filter_address}/) {
253 $self->{output}->output_add(long_msg =>
254 "skipping '" . $result->{address} . "': no matching address filter.",
255 debug => 1);
256 next;
257 }
258
259 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
260 $result->{group} !~ /$self->{option_results}->{filter_group}/) {
261 $self->{output}->output_add(long_msg =>
262 "skipping '" . $result->{group} . "': no matching group filter.",
263 debug => 1);
264 next;
265 }
266
267 $self->{ap}->{ $result->{name} } = {
268 instance => $instance,
269 display => $result->{name},
270 health => {
271 display => $result->{name}
272 }
273 };
274 }
275
276 if (scalar(keys %{$self->{ap}}) <= 0) {
277 $self->{output}->output_add(long_msg => 'no AP associated');
278 return;
279 }
280
281 $options{snmp}->load(
282 oids => [ map($_->{oid}, values(%$mapping_stat)) ],
283 instances => [ map($_->{instance}, values %{$self->{ap}}) ],
284 instance_regexp => '^(.*)$'
285 );
286 $snmp_result = $options{snmp}->get_leef();
287
288 foreach (sort keys %{$self->{ap}}) {
289 my $result = $options{snmp}->map_instance(
290 mapping => $mapping_stat,
291 results => $snmp_result,
292 instance => $self->{ap}->{$_}->{instance}
293 );
294
295 $self->{ap}->{$_}->{health}->{datalinkstate} = $result->{datalinkstate};
296 $self->{ap}->{$_}->{health}->{powersupply} = $result->{powersupply};
297 $self->{ap}->{$_}->{health}->{temperature} = $result->{temperature};
298 $self->{ap}->{$_}->{health}->{onlinetime} = $result->{onlinetime};
299 $self->{ap}->{$_}->{health}->{bootcount_total} = $result->{bootcount_total};
300 $self->{ap}->{$_}->{health}->{memory} = $result->{memory};
301 $self->{ap}->{$_}->{health}->{cpu} = $result->{cpu};
302 $self->{ap}->{$_}->{health}->{up_port_speed} = $result->{up_port_speed} * 1000;
303 $self->{ap}->{$_}->{health}->{up_port_per} = $result->{up_port_per};
304 $self->{ap}->{$_}->{health}->{online_user_num} = $result->{online_user_num};
305 }
306 }
307
308 1;
309
310 __END__
311
312 =head1 MODE
313
314 Check AP health.
315
316 =over 8
317
318 =item B<--filter-counters>
319
320 Only display some counters (regexp can be used).
321 Example: --filter-counters='^temperature|onlinetime$'
322
323 =item B<--filter-name>
324
325 Filter access point name (can be a regexp)
326
327 =item B<--filter-address>
328
329 Filter access point IP address (can be a regexp).
330
331 =item B<--filter-group>
332
333 Filter access point group (can be a regexp).
334
335 =item B<--warning-status>
336
337 Define the conditions to match for the status to be WARNING. (default: '%{powersupply} eq "limited"').
338 You can use the following variables: %{powersupply}, %{datalinkstate}, %{display}
339
340 =item B<--critical-status>
341
342 Define the conditions to match for the status to be CRITICAL (default: '%{powersupply} =~ /insufficient|limited/ || %{datalinkstate} !~ /run/').
343 You can use the following variables: %{powersupply}, %{datalinkstate}, %{display}
344
345 =item B<--warning-temperature>
346
347 Thresholds.
348
349 =item B<--critical-temperature>
350
351 Thresholds.
352
353 =item B<--warning-onlinetime>
354
355 Thresholds.
356
357 =item B<--critical-onlinetime>
358
359 Thresholds.
360
361 =item B<--warning-bootcount-total>
362
363 Thresholds.
364
365 =item B<--critical-bootcount-total>
366
367 Thresholds.
368
369 =item B<--warning-memory>
370
371 Thresholds.
372
373 =item B<--critical-memory>
374
375 Thresholds.
376
377
378 =item B<--warning-cpu>
379
380 Thresholds.
381
382 =item B<--critical-cpu>
383
384 Thresholds.
385
386 =item B<--warning-up-port-speed>
387
388 Thresholds.
389
390 =item B<--critical-up-port-speed>
391
392 Thresholds.
393
394 =item B<--warning-up-port-packet-err>
395
396 Thresholds.
397
398 =item B<--critical-up-port-packet-err>
399
400 Thresholds.
401
402 =item B<--warning-online-user-num>
403
404 Thresholds.
405
406 =item B<--critical-online-user-num>
407
408 Thresholds.
409
410 =back
411
412 =cut