Debian Codegraph @

src/centreon/common/aruba/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::aruba::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);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("Status is '%s' [Ip: %s][Group: %s][Location: %s]",
33 $self->{result_values}->{status},
34 $self->{result_values}->{ip},
35 $self->{result_values}->{group},
36 $self->{result_values}->{location}
37 );
38 return $msg;
39 }
40
41 sub custom_status_calc {
42 my ($self, %options) = @_;
43
44 $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_wlanAPName'};
45 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_wlanAPStatus'};
46 $self->{result_values}->{ip} = $options{new_datas}->{$self->{instance} . '_wlanAPIpAddress'};
47 $self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_wlanAPGroupName'};
48 $self->{result_values}->{location} = $options{new_datas}->{$self->{instance} . '_wlanAPLocation'};
49 return 0;
50 }
51
52 sub set_counters {
53 my ($self, %options) = @_;
54
55 $self->{maps_counters_type} = [
56 { name => 'global', type => 0, cb_init => 'skip_global' },
57 { name => 'ap', type => 1, cb_prefix_output => 'prefix_output',
58 message_multiple => 'All AP status are ok' },
59 ];
60
61 $self->{maps_counters}->{global} = [
62 { label => 'connected-current', nlabel => 'accesspoints.connected.current.count', set => {
63 key_values => [ { name => 'connected' } ],
64 output_template => 'Total connected AP: %d',
65 perfdatas => [
66 { value => 'connected', template => '%d', min => 0 },
67 ],
68 }
69 },
70 ];
71
72 $self->{maps_counters}->{ap} = [
73 { label => 'status', threshold => 0, set => {
74 key_values => [ { name => 'wlanAPName' }, { name => 'wlanAPIpAddress' }, { name => 'wlanAPGroupName' },
75 { name => 'wlanAPLocation' }, { name => 'wlanAPStatus' } ],
76 closure_custom_calc => $self->can('custom_status_calc'),
77 closure_custom_output => $self->can('custom_status_output'),
78 closure_custom_perfdata => sub { return 0; },
79 closure_custom_threshold_check => \&catalog_status_threshold,
80 }
81 },
82 { label => 'uptime', nlabel => 'accesspoint.uptime.seconds', set => {
83 key_values => [ { name => 'wlanAPUpTime' }, { name => 'wlanAPName' } ],
84 output_template => 'Uptime: %ss',
85 perfdatas => [
86 { value => 'wlanAPUpTime', template => '%s',
87 unit => 's', label_extra_instance => 1, instance_use => 'wlanAPName' },
88 ],
89 }
90 },
91 { label => 'controller-bootstrap', nlabel => 'accesspoint.controller.bootstrap.count', set => {
92 key_values => [ { name => 'wlanAPNumBootstraps' }, { name => 'wlanAPName' } ],
93 output_template => 'Controller Bootstrap Count: %d',
94 perfdatas => [
95 { value => 'wlanAPNumBootstraps', template => '%d',
96 label_extra_instance => 1, instance_use => 'wlanAPName' },
97 ],
98 }
99 },
100 { label => 'reboot', nlabel => 'accesspoint.reboot.count', set => {
101 key_values => [ { name => 'wlanAPNumReboots' }, { name => 'wlanAPName' } ],
102 output_template => 'Reboot Count: %d',
103 perfdatas => [
104 { value => 'wlanAPNumReboots', template => '%d',
105 label_extra_instance => 1, instance_use => 'wlanAPName' },
106 ],
107 }
108 },
109 ];
110 }
111
112 sub skip_global {
113 my ($self, %options) = @_;
114
115 scalar(keys %{$self->{ap}}) > 1 ? return(0) : return(1);
116 }
117
118 sub prefix_output {
119 my ($self, %options) = @_;
120
121 return "AP '" . $options{instance_value}->{wlanAPName} . "' ";
122 }
123
124 sub new {
125 my ($class, %options) = @_;
126 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
127 bless $self, $class;
128
129 $options{options}->add_options(arguments => {
130 'filter-ip:s' => { name => 'filter_ip' },
131 'filter-name:s' => { name => 'filter_name' },
132 'filter-group:s' => { name => 'filter_group' },
133 'warning-status:s' => { name => 'warning_status' },
134 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /up/i' },
135 });
136
137 return $self;
138 }
139
140 sub check_options {
141 my ($self, %options) = @_;
142 $self->SUPER::check_options(%options);
143
144 $self->change_macros(macros => ['warning_status', 'critical_status']);
145 }
146
147 my $map_status = { 1 => 'up', 2 => 'down' };
148
149 my $oid_wlsxWlanAPTable = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1';
150
151 my $mapping_info = {
152 wlanAPIpAddress => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.2' },
153 wlanAPName => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3' },
154 wlanAPGroupName => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.4' },
155 };
156 my $mapping_stat = {
157 wlanAPUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.12' },
158 wlanAPLocation => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.14' },
159 wlanAPStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.19', map => $map_status },
160 wlanAPNumBootstraps => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.20' },
161 wlanAPNumReboots => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.21' },
162 };
163
164 sub manage_selection {
165 my ($self, %options) = @_;
166
167 $self->{global}->{connected} = 0;
168 $self->{ap} = {};
169
170 my $snmp_info = $options{snmp}->get_table(
171 oid => $oid_wlsxWlanAPTable,
172 start => $mapping_info->{wlanAPIpAddress}->{oid},
173 end => $mapping_info->{wlanAPGroupName}->{oid},
174 nothing_quit => 1
175 );
176
177 foreach my $oid (keys %{$snmp_info}) {
178 next if ($oid !~ /^$mapping_info->{wlanAPIpAddress}->{oid}\.(.*)/);
179 my $instance = $1;
180
181 my $result = $options{snmp}->map_instance(
182 mapping => $mapping_info,
183 results => $snmp_info,
184 instance => $instance
185 );
186
187 if (defined($self->{option_results}->{filter_ip}) && $self->{option_results}->{filter_ip} ne '' &&
188 $result->{wlanAPIpAddress} !~ /$self->{option_results}->{filter_ip}/) {
189 $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPIpAddress} . "': no matching filter ip.", debug => 1);
190 next;
191 }
192 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
193 $result->{wlanAPName} !~ /$self->{option_results}->{filter_name}/) {
194 $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPName} . "': no matching filter name.", debug => 1);
195 next;
196 }
197 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
198 $result->{wlanAPGroupName} !~ /$self->{option_results}->{filter_group}/) {
199 $self->{output}->output_add(long_msg => "skipping '" . $result->{wlanAPGroupName} . "': no matching filter group.", debug => 1);
200 next;
201 }
202
203 $self->{ap}->{$instance} = { %{$result} };
204 }
205
206 if (scalar(keys %{$self->{ap}}) <= 0) {
207 $self->{output}->add_option_msg(short_msg => "No AP found.");
208 $self->{output}->option_exit();
209 }
210
211 $options{snmp}->load(
212 oids => [
213 $mapping_stat->{wlanAPUpTime}->{oid},
214 $mapping_stat->{wlanAPLocation}->{oid},
215 $mapping_stat->{wlanAPStatus}->{oid},
216 $mapping_stat->{wlanAPNumBootstraps}->{oid},
217 $mapping_stat->{wlanAPNumReboots}->{oid},
218 ],
219 instances => [ keys %{$self->{ap}} ],
220 instance_regexp => '^(.*)$'
221 );
222
223 my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
224
225 foreach my $oid (keys %{$snmp_result}) {
226 next if ($oid !~ /^$mapping_stat->{wlanAPUpTime}->{oid}\.(.*)/);
227 my $instance = $1;
228
229 my $result = $options{snmp}->map_instance(
230 mapping => $mapping_stat,
231 results => $snmp_result,
232 instance => $instance
233 );
234
235 $self->{ap}->{$instance} = { %{$self->{ap}->{$instance}}, %{$result}, wlanAPUpTime => $result->{wlanAPUpTime} / 100 };
236 $self->{global}->{connected}++;
237 }
238 }
239
240 1;
241
242 __END__
243
244 =head1 MODE
245
246 Check AP status (WLSX-WLAN-MIB).
247
248 =over 8
249
250 =item B<--warning-*> B<--critical-*>
251
252 Thresholds.
253 Can be: 'connected-current' (global), 'uptime',
254 'controller-bootstrap', 'reboot', 'status' (per AP).
255
256 'status' can use special variables like: %{name},
257 %{status}, %{ip}, %{group}, %{location} (default: '')
258
259 =item B<--filter-*>
260
261 Filter by 'ip', 'name', 'group' (regexp can be used).
262
263 =back
264
265 =cut