Debian Codegraph @

src/network/colubris/snmp/mode/apusage.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::colubris::snmp::mode::apusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = 'operational state: ' . $self->{result_values}->{state};
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
41 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
42 return 0;
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'global', type => 0 },
50 { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All access points are OK' },
51 ];
52
53 $self->{maps_counters}->{global} = [
54 { label => 'total-ap', set => {
55 key_values => [ { name => 'total_ap' } ],
56 output_template => 'total AP: %s',
57 perfdatas => [
58 { label => 'total_ap', value => 'total_ap', template => '%s', min => 0 },
59 ],
60 }
61 },
62 { label => 'total-users', set => {
63 key_values => [ { name => 'total_users' } ],
64 output_template => 'total users: %s',
65 perfdatas => [
66 { label => 'total_users', value => 'total_users', template => '%s', min => 0 },
67 ],
68 }
69 },
70 ];
71
72 $self->{maps_counters}->{ap} = [
73 { label => 'ap-status', threshold => 0, set => {
74 key_values => [ { name => 'state' }, { name => 'display' } ],
75 closure_custom_calc => $self->can('custom_status_calc'),
76 closure_custom_output => $self->can('custom_status_output'),
77 closure_custom_perfdata => sub { return 0; },
78 closure_custom_threshold_check => \&catalog_status_threshold,
79 }
80 },
81 { label => 'ap-users', set => {
82 key_values => [ { name => 'users' }, { name => 'display' } ],
83 output_template => 'current users: %s',
84 perfdatas => [
85 { label => 'ap_users', value => 'users', template => '%s',
86 min => 0, label_extra_instance => 1, instance_use => 'display' },
87 ],
88 }
89 },
90 ];
91 }
92
93 sub prefix_ap_output {
94 my ($self, %options) = @_;
95
96 return "AP '" . $options{instance_value}->{display} . "' ";
97 }
98
99 sub new {
100 my ($class, %options) = @_;
101 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
102 bless $self, $class;
103
104 $options{options}->add_options(arguments => {
105 'filter-name:s' => { name => 'filter_name' },
106 'check-device-without-ctrl' => { name => 'check_device_without_ctrl' },
107 'warning-ap-status:s' => { name => 'warning_ap_status', default => '' },
108 'critical-ap-status:s' => { name => 'critical_ap_status', default => '%{state} eq "disconnected"' },
109 });
110
111 return $self;
112 }
113
114 sub check_options {
115 my ($self, %options) = @_;
116 $self->SUPER::check_options(%options);
117
118 $self->change_macros(macros => ['warning_ap_status', 'critical_ap_status']);
119 }
120
121 my %map_device_state = (
122 1 => 'disconnected', 2 => 'authorized', 3 => 'join', 4 => 'firmware',
123 5 => 'security', 6 => 'configuration', 7 => 'running'
124 );
125
126 my $mapping = {
127 coDevDisState => { oid => '.1.3.6.1.4.1.8744.5.23.1.2.1.1.5', map => \%map_device_state },
128 coDevDisSystemName => { oid => '.1.3.6.1.4.1.8744.5.23.1.2.1.1.6' },
129 coDevDisControllerIndex => { oid => '.1.3.6.1.4.1.8744.5.23.1.2.1.1.11' },
130 };
131
132 my $mapping2 = {
133 coDevWirCliStaMACAddress => { oid => '.1.3.6.1.4.1.8744.5.25.1.7.1.1.2' },
134 };
135
136 sub manage_selection {
137 my ($self, %options) = @_;
138
139 $self->{cache_name} = "colubris_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
140 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
141 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
142
143 my $oid_coDeviceDiscoveryEntry = '.1.3.6.1.4.1.8744.5.23.1.2.1.1';
144 my $snmp_result = $options{snmp}->get_multiple_table(
145 oids => [
146 { oid => $oid_coDeviceDiscoveryEntry, start => $mapping->{coDevDisState}->{oid}, end => $mapping->{coDevDisSystemName}->{oid} },
147 { oid => $mapping->{coDevDisControllerIndex}->{oid} },
148 { oid => $mapping2->{coDevWirCliStaMACAddress}->{oid} },
149 ],
150 nothing_quit => 1,
151 return_type => 1
152 );
153
154 $self->{global} = { total_ap => 0, total_users => 0 };
155 $self->{ap} = {};
156 my @oids = $options{snmp}->oid_lex_sort(keys %$snmp_result);
157 my $checked = {};
158 foreach my $oid (reverse @oids) {
159 next if ($oid !~ /^$mapping->{coDevDisSystemName}->{oid}\.(.*)$/);
160 my $instance = $1;
161 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
162 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
163 $result->{coDevDisSystemName} !~ /$self->{option_results}->{filter_name}/) {
164 $self->{output}->output_add(long_msg => "skipping '" . $result->{coDevDisSystemName} . "': no matching filter.", debug => 1);
165 next;
166 }
167 if (!defined($self->{option_results}->{check_device_without_ctrl})) {
168 if ($result->{coDevDisControllerIndex} == 0) {
169 $self->{output}->output_add(long_msg => "skipping '" . $result->{coDevDisSystemName} . "': no controller associated.", debug => 1);
170 next;
171 }
172 }
173 if (defined($checked->{$result->{coDevDisSystemName}})) {
174 $self->{output}->output_add(long_msg => "skipping '" . $result->{coDevDisSystemName} . "': duplicated name.", debug => 1);
175 next;
176 }
177
178 $checked->{$result->{coDevDisSystemName}} = 1;
179 $self->{global}->{total_ap}++;
180 $self->{ap}->{$instance} = {
181 display => $result->{coDevDisSystemName},
182 state => $result->{coDevDisState},
183 users => 0,
184 };
185 }
186
187 foreach my $oid (sort keys %$snmp_result) {
188 next if ($oid !~ /^$mapping2->{coDevWirCliStaMACAddress}->{oid}\.(.*?)\./);
189 my $instance = $1;
190
191 next if (!defined($self->{ap}->{$instance}));
192
193 $self->{global}->{total_users}++;
194 $self->{ap}->{$instance}->{users}++;
195 }
196
197 if (scalar(keys %{$self->{ap}}) <= 0) {
198 $self->{output}->add_option_msg(short_msg => "No access point found.");
199 $self->{output}->option_exit();
200 }
201 }
202
203 1;
204
205 __END__
206
207 =head1 MODE
208
209 Check AP status and users connected.
210
211 =over 8
212
213 =item B<--filter-name>
214
215 Filter ap name with regexp.
216
217 =item B<--check-device-without-ctrl>
218
219 Check device even if it doesn't belongs to an controller team.
220
221 =item B<--warning-*>
222
223 Warning threshold.
224 Can be: 'total-ap', 'total-users', 'ap-users'.
225
226 =item B<--critical-*>
227
228 Critical threshold.
229 Can be: 'total-ap', 'total-users', 'ap-users'.
230
231 =item B<--warning-ap-status>
232
233 Define the conditions to match for the status to be WARNING.
234 You can use the following variables: %{state}, %{display}
235
236 =item B<--critical-ap-status>
237
238 Define the conditions to match for the status to be CRITICAL (default: '%{state} eq "disconnected"').
239 You can use the following variables: %{state}, %{display}
240
241 =back
242
243 =cut