Debian Codegraph @

src/network/cambium/cnpilot/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 package network::cambium::cnpilot::snmp::mode::radios;
21
22 use base qw(centreon::plugins::templates::counter);
23
24 use strict;
25 use warnings;
26 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
27 use Digest::MD5 qw(md5_hex);
28
29 sub prefix_radio_output {
30 my ($self, %options) = @_;
31
32 return "radio interface '" . $options{instance_value}->{name} . "' ";
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'radios', type => 1, cb_prefix_output => 'prefix_radio_output', message_multiple => 'All raadio interfaces are ok' }
40 ];
41
42 $self->{maps_counters}->{radios} = [
43 { label => 'clients-connected', nlabel => 'radio.clients.connected.count', set => {
44 key_values => [ { name => 'num_clients' }, { name => 'name' } ],
45 output_template => 'clients connected: %s',
46 perfdatas => [
47 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' }
48 ]
49 }
50 },
51 { label => 'status', type => 2, critical_default => '%{state} eq "off"',
52 set => {
53 key_values => [ { name => 'state' }, { name => 'name' } ],
54 output_template => 'state: %s',
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold_ng
57 }
58 },
59 { label => 'noise-floor', nlabel => 'radio.interface.noise.floor.dbm', set => {
60 key_values => [ { name => 'noise_floor' } ],
61 output_template => 'noise floor: %s dBm',
62 perfdatas => [
63 { template => '%s', min => 0, unit => 'dBm', label_extra_instance => 1, instance_use => 'name' }
64 ]
65 }
66 },
67 { label => 'interference', nlabel => 'radio.interface.interference.dbm', set => {
68 key_values => [ { name => 'interference' } ],
69 output_template => 'interference: %s dBm',
70 perfdatas => [
71 { template => '%s', min => 0, unit => 'dBm', label_extra_instance => 1, instance_use => 'name' }
72 ]
73 }
74 },
75 { label => 'traffic-in', nlabel => 'radio.interface.traffic.in.bitspersecond', set => {
76 key_values => [ { name => 'traffic_in', per_second => 1 } ],
77 output_template => 'in: %s %s/s',
78 output_change_bytes => 2,
79 perfdatas => [
80 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' }
81 ]
82 }
83 },
84 { label => 'traffic-out', nlabel => 'radio.interface.traffic.out.bitspersecond', set => {
85 key_values => [ { name => 'traffic_out', per_second => 1 } ],
86 output_template => 'out: %s %s/s',
87 output_change_bytes => 2,
88 perfdatas => [
89 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' }
90 ]
91 }
92 }
93 ];
94 }
95
96 sub new {
97 my ($class, %options) = @_;
98 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
99 bless $self, $class;
100
101 $options{options}->add_options(arguments => {
102 'filter-name:s' => { name => 'filter_name' }
103 });
104
105 return $self;
106 }
107
108 sub manage_selection {
109 my ($self, %options) = @_;
110
111 # Select relevant oids for radio monitoring
112 my $mapping = {
113 cambiumRadioMACAddress => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.2' },
114 cambiumRadioNumClients => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.5' },
115 cambiumRadioTxDataBytes => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.9' },
116 cambiumRadioRxDataBytes => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.10' },
117 cambiumRadioState => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.13' },
118 cambiumRadioNoiseFloor => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.16' },
119 cambiumRadioInterference => { oid => '.1.3.6.1.4.1.17713.22.1.2.1.17' }
120 };
121
122 # Point at the begining of the table
123 my $oid_cambiumRadioPointEntry = '.1.3.6.1.4.1.17713.22.1.2.1';
124
125 my $radio_result = $options{snmp}->get_table(
126 oid => $oid_cambiumRadioPointEntry,
127 nothing_quit => 1
128 );
129
130 foreach my $oid (keys %{$radio_result}) {
131 next if ($oid !~ /^$mapping->{cambiumRadioMACAddress}->{oid}\.(.*)$/);
132 # Catch instance in table
133 my $instance = $1;
134 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $radio_result, instance => $instance);
135
136 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
137 $result->{cambiumRadioMACAddress} !~ /$self->{option_results}->{filter_name}/);
138
139 $self->{radios}->{$instance} = {
140 name => $result->{cambiumRadioMACAddress},
141 num_clients => $result->{cambiumRadioNumClients},
142 state => lc($result->{cambiumRadioState}),
143 traffic_out => $result->{cambiumRadioTxDataBytes} * 8,
144 traffic_in => $result->{cambiumRadioRxDataBytes} * 8,
145 noise_floor => $result->{cambiumRadioNoiseFloor},
146 interference => $result->{cambiumRadioInterference}
147 };
148 }
149
150 if (scalar(keys %{$self->{radios}}) <= 0) {
151 $self->{output}->add_option_msg(short_msg => "No MACAddress matching with filter found.");
152 $self->{output}->option_exit();
153 }
154
155 $self->{cache_name} = 'cambium_cnpilot_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
156 md5_hex(
157 (defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '') . '_' .
158 (defined($self->{option_results}->{filter_name}) ? $self->{option_results}->{filter_name} : '')
159 );
160 }
161
162 1;
163
164 __END__
165
166 =head1 MODE
167
168 Check radio interfaces.
169
170 =over 8
171
172 =item B<--filter-counters>
173
174 Only display some counters (regexp can be used).
175 Example: --filter-counters='status'
176
177 =item B<--filter-name>
178
179 Filter interface by MACAdress
180
181 =item B<--warning-status>
182
183 Define the conditions to match for the status to be WARNING.
184 Can used special variables like: %{status}, %{name}
185
186 =item B<--critical-status>
187
188 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "expired"').
189 Can used special variables like: %{status}, %{name}
190
191 =item B<--warning-*> B<--critical-*>
192
193 Thresholds.
194 Can be: 'clients-connected', 'noise-floor', 'interference', 'traffic-in', 'traffic-out'.
195
196 =back
197
198 =cut