Debian Codegraph @

src/network/ruckus/smartzone/snmp/mode/accesspoints.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::ruckus::smartzone::snmp::mode::accesspoints;
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 catalog_status_calc);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 "connection status is '%s' [config status: '%s'] [registration status: '%s']",
35 $self->{result_values}->{connection_status},
36 $self->{result_values}->{config_status},
37 $self->{result_values}->{registration_status}
38 );
39 }
40
41 sub ap_long_output {
42 my ($self, %options) = @_;
43
44 return "checking access point '" . $options{instance_value}->{display} . "'";
45 }
46
47 sub prefix_ap_output {
48 my ($self, %options) = @_;
49
50 return "access point '" . $options{instance_value}->{display} . "' ";
51 }
52
53 sub set_counters {
54 my ($self, %options) = @_;
55
56 $self->{maps_counters_type} = [
57 { name => 'accesspoints', type => 3, cb_prefix_output => 'prefix_ap_output', cb_long_output => 'ap_long_output',
58 indent_long_output => ' ', message_multiple => 'All access points are ok',
59 group => [
60 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
61 { name => 'connection', type => 0, skipped_code => { -10 => 1 } },
62 { name => 'traffic', type => 0, skipped_code => { -10 => 1 } }
63 ]
64 }
65 ];
66
67 $self->{maps_counters}->{status} = [
68 { label => 'status', threshold => 0, set => {
69 key_values => [
70 { name => 'connection_status' }, { name => 'config_status' },
71 { name => 'registration_status' }, { name => 'display' }
72 ],
73 closure_custom_calc => \&catalog_status_calc,
74 closure_custom_output => $self->can('custom_status_output'),
75 closure_custom_perfdata => sub { return 0; },
76 closure_custom_threshold_check => \&catalog_status_threshold
77 }
78 }
79 ];
80
81 $self->{maps_counters}->{connection} = [
82 { label => 'connection-client-devices-authorized', nlabel => 'accesspoint.connection.client.devices.authorized.count', set => {
83 key_values => [ { name => 'authorized_clients' }, { name => 'display' } ],
84 output_template => 'client devices authorized connections: %d',
85 perfdatas => [
86 { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
87 ]
88 }
89 }
90 ];
91
92 $self->{maps_counters}->{traffic} = [
93 { label => 'traffic-in', nlabel => 'accesspoint.traffic.in.bitspersecond', set => {
94 key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ],
95 output_template => 'traffic in: %s%s/s',
96 output_change_bytes => 2,
97 perfdatas => [
98 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
99 ]
100 }
101 },
102 { label => 'traffic-out', nlabel => 'accesspoint.traffic.out.bitspersecond', set => {
103 key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ],
104 output_template => 'traffic out: %s%s/s',
105 output_change_bytes => 2,
106 perfdatas => [
107 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
108 ]
109 }
110 }
111 ];
112 }
113
114 sub new {
115 my ($class, %options) = @_;
116 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
117 bless $self, $class;
118
119 $options{options}->add_options(arguments => {
120 'filter-name:s' => { name => 'filter_name' },
121 'unknown-status:s' => { name => 'unknown_status', default => '' },
122 'warning-status:s' => { name => 'warning_status', default => '' },
123 'critical-status:s' => { name => 'critical_status', default => '' }
124 });
125
126 return $self;
127 }
128
129 sub check_options {
130 my ($self, %options) = @_;
131 $self->SUPER::check_options(%options);
132
133 $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
134 }
135
136 my $mapping = {
137 authorized_clients => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.15' }, # ruckusSZAPNumSta
138 connection_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.16' }, # ruckusSZAPConnStatus
139 registration_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.17' }, # ruckusSZAPRegStatus
140 config_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.18' }, # ruckusSZAPConfigStatus
141 traffic_out => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.57' }, # ruckusSZAPIpsecTXBytes
142 traffic_in => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.58' }, # ruckusSZAPIpsecRXBytes
143 };
144
145 sub manage_selection {
146 my ($self, %options) = @_;
147
148 my $oid_ruckusSZAPName = '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.5';
149 my $oid_ruckusSZAPSerial = '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.9';
150 my $snmp_result = $options{snmp}->get_multiple_table(
151 oids => [
152 { oid => $oid_ruckusSZAPName },
153 { oid => $oid_ruckusSZAPSerial }
154 ],
155 return_type => 1,
156 nothing_quit => 1
157 );
158
159 $self->{accesspoints} = {};
160 foreach (keys %$snmp_result) {
161 next if (! /^$oid_ruckusSZAPName\.(.*)/);
162 my $instance = $1;
163 my $name = defined($snmp_result->{$_}) && $snmp_result->{$_} ne '' ?
164 $snmp_result->{$_} : $snmp_result->{$oid_ruckusSZAPSerial . '.' . $instance};
165
166 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
167 $name !~ /$self->{option_results}->{filter_name}/) {
168 $self->{output}->output_add(long_msg => "skipping access point '" . $name . "'.", debug => 1);
169 next;
170 }
171
172 $self->{accesspoints}->{$instance} = {
173 display => $name,
174 status => { display => $name },
175 connection => { display => $name },
176 traffic => { display => $name }
177 };
178 }
179
180 return if (scalar(keys %{$self->{accesspoints}}) <= 0);
181
182 $options{snmp}->load(
183 oids => [ map($_->{oid}, values(%$mapping)) ],
184 instances => [ keys %{$self->{accesspoints}} ],
185 instance_regexp => '^(.*)$'
186 );
187 $snmp_result = $options{snmp}->get_leef();
188 foreach (keys %{$self->{accesspoints}}) {
189 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
190
191 $self->{accesspoints}->{$_}->{status}->{connection_status} = $result->{connection_status};
192 $self->{accesspoints}->{$_}->{status}->{registration_status} = $result->{registration_status};
193 $self->{accesspoints}->{$_}->{status}->{config_status} = $result->{config_status};
194
195 $self->{accesspoints}->{$_}->{connection}->{authorized_clients} = $result->{authorized_clients};
196
197 $self->{accesspoints}->{$_}->{traffic}->{traffic_in} = $result->{traffic_in} * 8;
198 $self->{accesspoints}->{$_}->{traffic}->{traffic_out} = $result->{traffic_out} * 8;
199 }
200
201 $self->{cache_name} = 'ruckus_smartzone_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
202 (defined($self->{option_results}->{filter_counters_block}) ? md5_hex($self->{option_results}->{filter_counters_block}) : md5_hex('all')) . '_' .
203 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
204 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'))
205 }
206
207 1;
208
209 __END__
210
211 =head1 MODE
212
213 Check access points.
214
215 =over 8
216
217 =item B<--filter-name>
218
219 Filter by access point name (can be a regexp).
220
221 =item B<--unknown-status>
222
223 Define the conditions to match for the status to be UNKNOWN.
224 You can use the following variables: %{config_status}, %{connection_status}, %{registration_status}
225
226 =item B<--warning-status>
227
228 Define the conditions to match for the status to be WARNING.
229 You can use the following variables: %{config_status}, %{connection_status}, %{registration_status}
230
231 =item B<--critical-status>
232
233 Define the conditions to match for the status to be CRITICAL.
234 You can use the following variables: %{config_status}, %{connection_status}, %{registration_status}
235
236 =item B<--warning-*> B<--critical-*>
237
238 Thresholds.
239 Can be: 'traffic-in', 'traffic-out', 'connection-client-devices-authorized'.
240
241 =back
242
243 =cut