Debian Codegraph @

src/network/ubiquiti/airfiber/snmp/mode/radios.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::ubiquiti::airfiber::snmp::mode::radios;
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_ng);
28 use Digest::MD5 qw(md5_hex);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'state: %s [enabled: %s]',
35 $self->{result_values}->{state},
36 $self->{result_values}->{enabled}
37 );
38 }
39
40 sub radio_long_output {
41 my ($self, %options) = @_;
42
43 return sprintf(
44 "checking radio interface '%s'",
45 $options{instance_value}->{name}
46 );
47 }
48
49 sub prefix_radio_output {
50 my ($self, %options) = @_;
51
52 return sprintf(
53 "radio interface '%s' ",
54 $options{instance_value}->{name}
55 );
56 }
57
58 sub prefix_signal_output {
59 my ($self, %options) = @_;
60
61 return 'signal ';
62 }
63
64 sub prefix_traffic_output {
65 my ($self, %options) = @_;
66
67 return 'traffic ';
68 }
69
70 sub set_counters {
71 my ($self, %options) = @_;
72
73 $self->{maps_counters_type} = [
74 { name => 'radios', type => 3, cb_prefix_output => 'prefix_radio_output', cb_long_output => 'radio_long_output',
75 indent_long_output => ' ', message_multiple => 'All radio interfaces are ok',
76 group => [
77 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
78 { name => 'signal', type => 0, cb_prefix_output => 'prefix_signal_output', skipped_code => { -10 => 1 } },
79 { name => 'traffic', type => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1 } }
80 ]
81 }
82 ];
83
84 $self->{maps_counters}->{status} = [
85 {
86 label => 'status', type => 2, critical_default => '%{enabled} eq "yes" and %{state} eq "down"',
87 set => {
88 key_values => [ { name => 'enabled' }, { name => 'state' }, { name => 'name' } ],
89 closure_custom_output => $self->can('custom_status_output'),
90 closure_custom_perfdata => sub { return 0; },
91 closure_custom_threshold_check => \&catalog_status_threshold_ng
92 }
93 }
94 ];
95
96 $self->{maps_counters}->{signal} = [
97 { label => 'chain0-signal-receive-power', nlabel => 'radio.interface.chain0.signal.receive.power.dbm', set => {
98 key_values => [ { name => 'chain0_in_power' } ],
99 output_template => 'chain0 receive power: %s dBm',
100 perfdatas => [
101 { template => '%s', min => 0, unit => 'dBm', label_extra_instance => 1 }
102 ]
103 }
104 },
105 { label => 'chain1-signal-receive-power', nlabel => 'radio.interface.chain1.signal.receive.power.dbm', set => {
106 key_values => [ { name => 'chain1_in_power' } ],
107 output_template => 'chain1 receive power: %s dBm',
108 perfdatas => [
109 { template => '%s', min => 0, unit => 'dBm', label_extra_instance => 1 }
110 ]
111 }
112 }
113 ];
114
115 $self->{maps_counters}->{traffic} = [
116 { label => 'traffic-in', nlabel => 'radio.interface.traffic.in.bitspersecond', set => {
117 key_values => [ { name => 'traffic_in', per_second => 1 } ],
118 output_template => 'in: %s %s/s',
119 output_change_bytes => 2,
120 perfdatas => [
121 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 }
122 ]
123 }
124 },
125 { label => 'traffic-out', nlabel => 'radio.interface.traffic.out.bitspersecond', set => {
126 key_values => [ { name => 'traffic_out', per_second => 1 } ],
127 output_template => 'out: %s %s/s',
128 output_change_bytes => 2,
129 perfdatas => [
130 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 }
131 ]
132 }
133 }
134 ];
135 }
136
137 sub new {
138 my ($class, %options) = @_;
139 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
140 bless $self, $class;
141
142 $options{options}->add_options(arguments => {
143 'filter-name:s' => { name => 'filter_name' }
144 });
145
146 return $self;
147 }
148
149 my $map_state = { 0 => 'down', 1 => 'up' };
150 my $map_enabled = { 1 => 'yes', 2 => 'no' };
151
152 my $mapping = {
153 enabled => { oid => '.1.3.6.1.4.1.41112.1.3.1.1.2', map => $map_enabled }, # radioEnable
154 state => { oid => '.1.3.6.1.4.1.41112.1.3.2.1.26', map => $map_state }, # radioLinkState
155 chain0_in_power => { oid => '.1.3.6.1.4.1.41112.1.3.2.1.11' }, # rxPower0
156 chain1_in_power => { oid => '.1.3.6.1.4.1.41112.1.3.2.1.14' }, # rxPower1
157 total_out => { oid => '.1.3.6.1.4.1.41112.1.3.3.1.6' }, # txOctetsOK
158 total_in => { oid => '.1.3.6.1.4.1.41112.1.3.3.1.19' } # rxTotalOctets
159 };
160
161 sub manage_selection {
162 my ($self, %options) = @_;
163
164 $self->{cache_name} = 'ubiquiti_airfiber_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
165 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
166 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
167
168 my $oid_name = '.1.3.6.1.4.1.41112.1.3.1.1.14'; # linkName
169 my $snmp_result = $options{snmp}->get_table(
170 oid => $oid_name,
171 nothing_quit => 1
172 );
173
174 $self->{radios} = {};
175 foreach (keys %$snmp_result) {
176 /\.(\d+)$/;
177 my $instance = $1;
178
179 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
180 $snmp_result->{$_} !~ /$self->{option_results}->{filter_name}/) {
181 $self->{output}->output_add(long_msg => "skipping radio interface '" . $snmp_result->{$_} . "'.", debug => 1);
182 next;
183 }
184
185 $self->{radios}->{ $snmp_result->{$_} } = {
186 name => $snmp_result->{$_},
187 instance => $instance
188 };
189 }
190
191 return if (scalar(keys %{$self->{radios}}) <= 0);
192
193 $options{snmp}->load(
194 oids => [ map($_->{oid}, values(%$mapping)) ],
195 instances => [ map($_->{instance}, values(%{$self->{radios}})) ],
196 instance_regexp => '^(.*)$'
197 );
198 $snmp_result = $options{snmp}->get_leef();
199 foreach (keys %{$self->{radios}}) {
200 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{radios}->{$_}->{instance});
201
202 $self->{radios}->{$_}->{status} = { state => $result->{state}, enabled => $result->{enabled}, name => $_ };
203 $self->{radios}->{$_}->{traffic} = { traffic_in => $result->{total_in} * 8, traffic_out => $result->{total_out} * 8 };
204 $self->{radios}->{$_}->{signal} = { chain0_in_power => $result->{chain0_in_power}, chain1_in_power => $result->{chain1_in_power} };
205 }
206 }
207
208 1;
209
210 __END__
211
212 =head1 MODE
213
214 Check radio interfaces.
215
216 =over 8
217
218 =item B<--filter-name>
219
220 Filter interface by name (can be a regexp).
221
222 =item B<--unknown-status>
223
224 Define the conditions to match for the status to be UNKNOWN.
225 You can use the following variables: %{enabled}, %{state}, %{name}
226
227 =item B<--warning-status>
228
229 Define the conditions to match for the status to be WARNING.
230 You can use the following variables: %{enabled}, %{state}, %{name}
231
232 =item B<--critical-status>
233
234 Define the conditions to match for the status to be CRITICAL (default: '%{enabled} eq "yes" and %{state} eq "down"').
235 You can use the following variables: %{enabled}, %{state}, %{name}
236
237 =item B<--warning-*> B<--critical-*>
238
239 Thresholds.
240 Can be: 'traffic-in', 'traffic-out', 'chain0-signal-receive-power', 'chain1-signal-receive-power'.
241
242 =back
243
244 =cut