Debian Codegraph @

src/centreon/common/airespace/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::airespace::snmp::mode::apusers;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub prefix_global_output {
29 my ($self, %options) = @_;
30
31 return 'Users ';
32 }
33
34 sub prefix_ssid_output {
35 my ($self, %options) = @_;
36
37 return "SSID '" . $options{instance_value}->{display} . "' ";
38 }
39
40 sub prefix_ap_output {
41 my ($self, %options) = @_;
42
43 return "Access point '" . $options{instance_value}->{display} . "' ";
44 }
45
46 sub set_counters {
47 my ($self, %options) = @_;
48
49 $self->{maps_counters_type} = [
50 { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 },
51 { name => 'ssid', type => 1, cb_prefix_output => 'prefix_ssid_output', message_multiple => 'All users by SSID are ok' },
52 { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All users by access point are ok' }
53 ];
54
55 $self->{maps_counters}->{global} = [
56 { label => 'total', nlabel => 'users.total.count', set => {
57 key_values => [ { name => 'total' } ],
58 output_template => 'total: %s',
59 perfdatas => [
60 { label => 'total', template => '%s', unit => 'users', min => 0 },
61 ]
62 }
63 },
64 { label => 'total-idle', nlabel => 'users.idle.count', set => {
65 key_values => [ { name => 'total_idle' } ],
66 output_template => 'idle: %s',
67 perfdatas => [
68 { label => 'total_idle', template => '%s', unit => 'users', min => 0 }
69 ]
70 }
71 },
72 { label => 'total-aaapending', nlabel => 'users.aaapending.count', set => {
73 key_values => [ { name => 'total_aaapending' } ],
74 output_template => 'aaaPending: %s',
75 perfdatas => [
76 { label => 'total_aaapending', template => '%s', unit => 'users', min => 0 }
77 ]
78 }
79 },
80 { label => 'total-authenticated', nlabel => 'users.authenticated.count', set => {
81 key_values => [ { name => 'total_authenticated' } ],
82 output_template => 'authenticated: %s',
83 perfdatas => [
84 { label => 'total_authenticated', template => '%s', unit => 'users', min => 0 }
85 ]
86 }
87 },
88 { label => 'total-associated', nlabel => 'users.associated.count', set => {
89 key_values => [ { name => 'total_associated' } ],
90 output_template => 'associated: %s',
91 perfdatas => [
92 { label => 'total_associated', template => '%s', unit => 'users', min => 0 }
93 ]
94 }
95 },
96 { label => 'total-disassociated', nlabel => 'users.disassociated.count', set => {
97 key_values => [ { name => 'total_disassociated' } ],
98 output_template => 'disassociated: %s',
99 perfdatas => [
100 { label => 'total_disassociated', template => '%s', unit => 'users', min => 0 }
101 ]
102 }
103 },
104 { label => 'total-powersave', nlabel => 'users.powersave.count', set => {
105 key_values => [ { name => 'total_powersave' } ],
106 output_template => 'powersave: %s',
107 perfdatas => [
108 { label => 'total_powersave', template => '%s', unit => 'users', min => 0 }
109 ]
110 }
111 },
112 { label => 'total-tobedeleted', nlabel => 'users.tobedeleted.count', set => {
113 key_values => [ { name => 'total_tobedeleted' } ],
114 output_template => 'to be deleted: %s',
115 perfdatas => [
116 { label => 'total_tobedeleted', template => '%s', unit => 'users', min => 0 }
117 ]
118 }
119 },
120 { label => 'total-probing', nlabel => 'users.probing.count', set => {
121 key_values => [ { name => 'total_probing' } ],
122 output_template => 'probing: %s',
123 perfdatas => [
124 { label => 'total_probing', template => '%s', unit => 'users', min => 0 }
125 ]
126 }
127 },
128 { label => 'total-blacklisted', nlabel => 'users.blacklisted.count', set => {
129 key_values => [ { name => 'total_blacklisted' } ],
130 output_template => 'blacklisted: %s',
131 perfdatas => [
132 { label => 'total_blacklisted', template => '%s', unit => 'users', min => 0 }
133 ]
134 }
135 }
136 ];
137
138 $self->{maps_counters}->{ssid} = [
139 { label => 'ssid', nlabel => 'ssid.users.total.count', set => {
140 key_values => [ { name => 'total' }, { name => 'display' } ],
141 output_template => 'users: %s',
142 perfdatas => [
143 { label => 'ssid', template => '%s', unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' },
144 ]
145 }
146 }
147 ];
148
149 $self->{maps_counters}->{ap} = [
150 { label => 'ap', nlabel => 'accesspoint.users.total.count', set => {
151 key_values => [ { name => 'total' }, { name => 'display' } ],
152 output_template => 'users: %s',
153 perfdatas => [
154 { label => 'ap', template => '%s', unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' }
155 ]
156 }
157 }
158 ];
159 }
160
161 sub new {
162 my ($class, %options) = @_;
163 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
164 bless $self, $class;
165
166 $options{options}->add_options(arguments => {
167 'filter-ssid:s' => { name => 'filter_ssid' },
168 'filter-ap:s' => { name => 'filter_ap' },
169 'filter-group:s' => { name => 'filter_group' },
170 'ignore-ap-users' => { name => 'ignore_ap_users' }
171 });
172
173 return $self;
174 }
175
176 my $map_station_status = {
177 0 => 'idle',
178 1 => 'aaapending',
179 2 => 'authenticated',
180 3 => 'associated',
181 4 => 'powersave',
182 5 => 'disassociated',
183 6 => 'tobedeleted',
184 7 => 'probing',
185 8 => 'blacklisted'
186 };
187 my $mapping = {
188 ssid => { oid => '.1.3.6.1.4.1.14179.2.1.4.1.7' }, # bsnMobileStationSsid
189 status => { oid => '.1.3.6.1.4.1.14179.2.1.4.1.9', map => $map_station_status } # bsnMobileStationStatus
190 };
191 my $mapping2 = {
192 ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
193 group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName
194 };
195
196 my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3';
197 my $oid_bsnDot11EssSsid = '.1.3.6.1.4.1.14179.2.1.1.1.2';
198 my $oid_bsnAPIfLoadNumOfClients = '.1.3.6.1.4.1.14179.2.2.13.1.4';
199
200 sub manage_selection {
201 my ($self, %options) = @_;
202
203 my $snmp_result = $options{snmp}->get_multiple_table(
204 oids => [
205 { oid => $oid_agentInventoryMachineModel },
206 { oid => $mapping->{status}->{oid} },
207 { oid => $mapping->{ssid}->{oid} },
208 { oid => $oid_bsnDot11EssSsid }
209 ],
210 return_type => 1,
211 nothing_quit => 1
212 );
213 $self->{output}->output_add(
214 long_msg => "Model: " .
215 (defined($self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'}) ? $self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'} : 'unknown')
216 );
217
218 $self->{global} = {
219 total => 0, total_idle => 0, total_aaapending => 0, total_authenticated => 0,
220 total_associated => 0, total_powersave => 0, total_disassociated => 0,
221 total_tobedeleted => 0, total_probing => 0, total_blacklisted => 0
222 };
223 $self->{ssid} = {};
224 foreach my $oid (keys %$snmp_result) {
225 if ($oid =~ /^$oid_bsnDot11EssSsid/ && !defined($self->{ssid}->{ $snmp_result->{$oid} })) {
226 if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' &&
227 $snmp_result->{$oid} !~ /$self->{option_results}->{filter_ssid}/) {
228 $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid} . "': no matching filter.", debug => 1);
229 next;
230 }
231 $self->{ssid}->{ $snmp_result->{$oid} } = { display => $snmp_result->{$oid}, total => 0 };
232 next;
233 }
234 next if ($oid !~ /^$mapping->{ssid}->{oid}\.(.*)$/);
235 my $instance = $1;
236 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
237 if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' &&
238 $result->{ssid} !~ /$self->{option_results}->{filter_ssid}/) {
239 $self->{output}->output_add(long_msg => "skipping '" . $result->{ssid} . "': no matching filter.", debug => 1);
240 next;
241 }
242
243 $self->{ssid}->{ $result->{ssid} } = { display => $result->{ssid}, total => 0 } if (!defined($self->{ssid}->{ $result->{ssid} }));
244 $self->{ssid}->{ $result->{ssid} }->{total}++;
245 $self->{global}->{total}++;
246 $self->{global}->{'total_' . $result->{status}}++;
247 }
248
249 return if (defined($self->{option_results}->{ignore_ap_users}));
250
251 my $request = [ { oid => $mapping2->{ap_name}->{oid} }, { oid => $oid_bsnAPIfLoadNumOfClients } ];
252 push @$request, { oid => $mapping2->{group_name}->{oid} }
253 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
254 $snmp_result = $options{snmp}->get_multiple_table(
255 oids => $request,
256 return_type => 1
257 );
258
259 # check by ap
260 $self->{ap} = {};
261 foreach my $oid (keys %$snmp_result) {
262 next if ($oid !~ /^$mapping2->{ap_name}->{oid}\.(.*)/);
263 my $instance = $1;
264 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance);
265 if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' &&
266 $result->{ap_name} !~ /$self->{option_results}->{filter_ap}/) {
267 $self->{output}->output_add(long_msg => "skipping access point '" . $result->{ap_name} . "': no matching filter.", debug => 1);
268 next;
269 }
270 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
271 $result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
272 $self->{output}->output_add(long_msg => "skipping access point '" . $result->{ap_name} . "': no matching filter.", debug => 1);
273 next;
274 }
275
276 foreach my $oid2 (keys %$snmp_result) {
277 next if ($oid2 !~ /^$oid_bsnAPIfLoadNumOfClients\.$instance\./);
278 $self->{ap}->{$instance} = { display => $result->{ap_name}, total => 0 } if (!defined($self->{ap}->{$instance}));
279 $self->{ap}->{$instance}->{total} += $snmp_result->{$oid2};
280 }
281 }
282 }
283
284 1;
285
286 __END__
287
288 =head1 MODE
289
290 Check users connected (total, by SSID, by AP).
291
292 =over 8
293
294 =item B<--filter-counters>
295
296 Only display some counters (regexp can be used).
297 Example: --filter-counters='^total|total-idle$'
298
299 =item B<--filter-ssid>
300
301 Filter by SSID (can be a regexp).
302
303 =item B<--filter-ap>
304
305 Filter by access point name (can be a regexp).
306
307 =item B<--filter-group>
308
309 Filter by access point group (can be a regexp).
310
311 =item B<--ignore-ap-users>
312
313 Unmonitor users by access points.
314
315 =item B<--warning-*> B<--critical-*>
316
317 Thresholds.
318 Can be: 'total', 'total-idle', 'total-aaapending', 'total-authenticated',
319 'total-associated', 'total-powersave', 'total-disassociated', 'total-tobedeleted',
320 'total-probing', 'total-blacklisted', 'ssid', 'ap'.
321
322 =back
323
324 =cut