Debian Codegraph @

src/centreon/common/aruba/snmp/mode/apusers.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::apusers;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'global', type => 0 },
33 { name => 'essid', type => 1, cb_prefix_output => 'prefix_essid_output', message_multiple => 'All users by ESSID are ok' },
34 { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All users by AP are ok' }
35 ];
36 $self->{maps_counters}->{global} = [
37 { label => 'total', set => {
38 key_values => [ { name => 'total' } ],
39 output_template => 'Total Users: %s',
40 perfdatas => [
41 { label => 'total', template => '%s', unit => 'users', min => 0 }
42 ]
43 }
44 },
45 { label => 'total-none', set => {
46 key_values => [ { name => 'total_none' } ],
47 output_template => 'Total Auth None: %s',
48 perfdatas => [
49 { label => 'total_none', template => '%s', unit => 'users', min => 0 }
50 ]
51 }
52 },
53 { label => 'total-other', set => {
54 key_values => [ { name => 'total_other' } ],
55 output_template => 'Total Auth Other: %s',
56 perfdatas => [
57 { label => 'total_other', template => '%s', unit => 'users', min => 0 }
58 ]
59 }
60 },
61 { label => 'total-web', set => {
62 key_values => [ { name => 'total_web' } ],
63 output_template => 'Total Auth Web: %s',
64 perfdatas => [
65 { label => 'total_web', template => '%s', unit => 'users', min => 0 }
66 ]
67 }
68 },
69 { label => 'total-dot1x', set => {
70 key_values => [ { name => 'total_dot1x' } ],
71 output_template => 'Total Auth Dot1x: %s',
72 perfdatas => [
73 { label => 'total_dot1x', template => '%s', unit => 'users', min => 0 }
74 ]
75 }
76 },
77 { label => 'total-vpn', set => {
78 key_values => [ { name => 'total_vpn' } ],
79 output_template => 'Total Auth Vpn: %s',
80 perfdatas => [
81 { label => 'total_vpn', template => '%s', unit => 'users', min => 0 }
82 ]
83 }
84 },
85 { label => 'total-mac', set => {
86 key_values => [ { name => 'total_mac' } ],
87 output_template => 'Total Auth Mac: %s',
88 perfdatas => [
89 { label => 'total_mac', template => '%s', unit => 'users', min => 0 }
90 ]
91 }
92 },
93 { label => 'avg-connection-time', set => {
94 key_values => [ { name => 'avg_connection_time' } ],
95 output_template => 'Users average connection time: %.3f seconds',
96 perfdatas => [
97 { label => 'avg_connection_time', template => '%.3f', unit => 's', min => 0 }
98 ]
99 }
100 }
101 ];
102
103 $self->{maps_counters}->{essid} = [
104 { label => 'total-essid', set => {
105 key_values => [ { name => 'users' }, { name => 'essid' } ],
106 output_template => 'users: %s',
107 perfdatas => [
108 { label => 'essid', template => '%s',
109 unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'essid' }
110 ]
111 }
112 }
113 ];
114
115 $self->{maps_counters}->{ap} = [
116 { label => 'total-ap', set => {
117 key_values => [ { name => 'users' }, { name => 'ap_id' } ],
118 output_template => 'users: %s',
119 perfdatas => [
120 { label => 'ap', template => '%s',
121 unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'ap_id' }
122 ]
123 }
124 }
125 ];
126 }
127
128 sub prefix_essid_output {
129 my ($self, %options) = @_;
130
131 return "ESSID '" . $options{instance_value}->{essid} . "' ";
132 }
133
134 sub prefix_ap_output {
135 my ($self, %options) = @_;
136
137 return "AP '" . $options{instance_value}->{ap_id} . "' ";
138 }
139
140 sub new {
141 my ($class, %options) = @_;
142 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
143 bless $self, $class;
144
145 $options{options}->add_options(arguments => {
146 'filter-ip-address:s' => { name => 'filter_ip_address' },
147 'filter-bssid:s' => { name => 'filter_bssid' },
148 'filter-essid:s' => { name => 'filter_essid' }
149 });
150
151 return $self;
152 }
153
154 my $map_auth_method = {
155 0 => 'none', 1 => 'web',
156 2 => 'mac', 3 => 'vpn',
157 4 => 'dot1x', 5 => 'kerberos',
158 7 => 'secureId',
159 15 => 'pubcookie', 16 => 'xSec',
160 17 => 'xSecMachine',
161 28 => 'via-vpn',
162 255 => 'other'
163 };
164 my $map_role = {
165 1 => 'master',
166 2 => 'local',
167 3 => 'standbymaster'
168 };
169 my $mapping = {
170 nUserUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.5' },
171 nUserAuthenticationMethod => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.6', map => $map_auth_method }
172 };
173 my $mapping2 = {
174 nUserApBSSID => { oid => '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1.11' }
175 };
176
177 my $oid_wlsxUserEntry = '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1';
178 my $oid_wlsxSwitchRole = '.1.3.6.1.4.1.14823.2.2.1.1.1.4';
179 my $oid_apESSID = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.2';
180 my $oid_apIpAddress = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.5';
181 #my $oid_wlanAPName = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3';
182
183 sub manage_selection {
184 my ($self, %options) = @_;
185
186 $self->{global} = {
187 total => 0, total_none => 0, total_web => 0, total_mac => 0, total_vpn => 0,
188 total_dot1x => 0, total_kerberos => 0, total_secureId => 0, total_pubcookie => 0,
189 total_xSec => 0, xSecMachine => 0, 'total_via-vpn' => 0, total_other => 0
190 };
191 $self->{ap} = {};
192 $self->{essid} = {};
193
194 my $snmp_result = $options{snmp}->get_multiple_table(
195 oids => [
196 { oid => $oid_wlsxSwitchRole },
197 { oid => $oid_wlsxUserEntry, start => $mapping->{nUserUpTime}->{oid}, end => $mapping->{nUserAuthenticationMethod}->{oid} },
198 { oid => $mapping2->{nUserApBSSID}->{oid} },
199 { oid => $oid_apESSID },
200 { oid => $oid_apIpAddress }
201 ],
202 nothing_quit => 1
203 );
204
205 my $role = $map_role->{ $snmp_result->{$oid_wlsxSwitchRole}->{$oid_wlsxSwitchRole . '.0'} };
206 if ($role =~ /standbymaster/) {
207 $self->{output}->output_add(
208 severity => 'OK',
209 short_msg => "Cannot get information. Switch role is '" . $role . "'."
210 );
211 $self->{output}->display();
212 $self->{output}->exit();
213 }
214
215 my $map_ap = {};
216 foreach my $oid (keys %{$snmp_result->{$oid_apESSID}}) {
217 $oid =~ /^$oid_apESSID\.(.*)$/;
218 $map_ap->{$1} = { essid => $snmp_result->{$oid_apESSID}->{$oid}, ip => $snmp_result->{$oid_apIpAddress}->{$oid_apIpAddress . '.' . $1} };
219 }
220
221 my $total_timeticks = 0;
222 foreach my $oid (keys %{$snmp_result->{$oid_wlsxUserEntry}}) {
223 next if ($oid !~ /^$mapping->{nUserAuthenticationMethod}->{oid}\.(.*)$/);
224 my $instance = $1;
225 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_wlsxUserEntry}, instance => $instance);
226 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{ $mapping2->{nUserApBSSID}->{oid} }, instance => $instance);
227
228 # security
229 next if (!defined($result2->{nUserApBSSID}));
230 my $bssid = join('.', unpack('C*', $result2->{nUserApBSSID}));
231 next if (defined($self->{option_results}->{filter_ip_address}) && $self->{option_results}->{filter_ip_address} ne '' &&
232 defined($map_ap->{$bssid}) && $map_ap->{$bssid}->{ip} !~ /$self->{option_results}->{filter_ip_address}/);
233 next if (defined($self->{option_results}->{filter_essid}) && $self->{option_results}->{filter_essid} ne '' &&
234 defined($map_ap->{$bssid}) && $map_ap->{$bssid}->{essid} !~ /$self->{option_results}->{filter_essid}/);
235 next if (defined($self->{option_results}->{filter_bssid}) && $self->{option_results}->{filter_bssid} ne '' &&
236 $bssid !~ /$self->{option_results}->{filter_bssid}/);
237
238 my $ap_id = $bssid;
239 #$ap_id = $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid}
240 # if (defined($self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid}) && $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} ne '');
241 $self->{ap}->{$bssid} = { users => 0, ap_id => $ap_id } if (!defined($self->{ap}->{$bssid}));
242 $self->{ap}->{$bssid}->{users}++;
243
244 if (defined($map_ap->{$bssid})) {
245 $self->{essid}->{ $map_ap->{$bssid}->{essid} } = { users => 0, essid => $map_ap->{$bssid}->{essid} } if (!defined($self->{essid}->{ $map_ap->{$bssid}->{essid} }));
246 $self->{essid}->{ $map_ap->{$bssid}->{essid} }->{users}++;
247 }
248
249 $self->{global}->{total}++;
250 $self->{global}->{'total_' . $result->{nUserAuthenticationMethod}}++;
251 $total_timeticks += $result->{nUserUpTime};
252 }
253
254 if ($self->{global}->{total} > 0) {
255 $self->{global}->{avg_connection_time} = $total_timeticks / $self->{global}->{total} * 0.01;
256 }
257 }
258
259 1;
260
261 __END__
262
263 =head1 MODE
264
265 Check total users connected (deprecated).
266
267 =over 8
268
269 =item B<--warning-*>
270
271 Warning threshold.
272 Can be: 'total', 'total-none', 'total-other', 'total-web',
273 'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds),
274 'total-ap', 'total-essid'.
275
276 =item B<--critical-*>
277
278 Critical threshold.
279 Can be: 'total', 'total-none', 'total-other', 'total-web',
280 'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds),
281 'total-ap', 'total-essid'.
282
283 =item B<--filter-ip-address>
284
285 Filter by ip address (regexp can be used).
286
287 =item B<--filter-essid>
288
289 Filter by ESSID (regexp can be used).
290
291 =item B<--filter-bssid>
292
293 Filter by BSSID (regexp can be used).
294
295 =back
296
297 =cut