Debian Codegraph @

src/centreon/common/airespace/snmp/mode/apchannelnoise.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::apchannelnoise;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub ap_long_output {
29 my ($self, %options) = @_;
30
31 return "checking access point '" . $options{instance_value}->{display} . "'";
32 }
33
34 sub prefix_ap_output {
35 my ($self, %options) = @_;
36
37 return "access point '" . $options{instance_value}->{display} . "' ";
38 }
39
40 sub prefix_channel_output {
41 my ($self, %options) = @_;
42
43 return "channel '" . $options{instance_value}->{display} . "' ";
44 }
45
46 sub set_counters {
47 my ($self, %options) = @_;
48
49 $self->{maps_counters_type} = [
50 { name => 'ap', type => 3, cb_prefix_output => 'prefix_ap_output', cb_long_output => 'ap_long_output', indent_long_output => ' ', message_multiple => 'All access points are ok',
51 group => [
52 { name => 'channels', display_long => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'channels are ok', type => 1, skipped_code => { -10 => 1 } }
53 ]
54 }
55 ];
56
57 $self->{maps_counters}->{channels} = [
58 { label => 'noise-power', nlabel => 'accesspoint.noise.power.dbm', set => {
59 key_values => [ { name => 'noise_power' }, { name => 'display' } ],
60 output_template => 'noise power: %s dBm',
61 perfdatas => [
62 { label => 'noise_power', template => '%s', unit => 'dBm', label_extra_instance => 1 }
63 ]
64 }
65 }
66 ];
67 }
68
69 sub new {
70 my ($class, %options) = @_;
71 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
72 bless $self, $class;
73
74 $options{options}->add_options(arguments => {
75 'filter-name:s' => { name => 'filter_name' },
76 'filter-channel:s' => { name => 'filter_channel' },
77 'filter-group:s' => { name => 'filter_group' }
78 });
79
80 return $self;
81 }
82
83 my $map_admin_status = {
84 1 => 'enable', 2 => 'disable'
85 };
86 my $mapping = {
87 ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
88 group_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.30' } # bsnAPGroupVlanName
89 };
90 my $oid_bsnAPIfDBNoisePower = '.1.3.6.1.4.1.14179.2.2.15.1.21';
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $request = [
96 { oid => $mapping->{ap_name}->{oid} },
97 { oid => $oid_bsnAPIfDBNoisePower }
98 ];
99 push @$request, { oid => $mapping->{group_name}->{oid} }
100 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
101
102 my $snmp_result = $options{snmp}->get_multiple_table(
103 oids => $request,
104 return_type => 1,
105 nothing_quit => 1
106 );
107
108 foreach (keys %$snmp_result) {
109 next if (! /^$mapping->{ap_name}->{oid}\.(.*)/);
110 my $instance = $1;
111
112 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
113 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
114 $result->{ap_name} !~ /$self->{option_results}->{filter_name}/) {
115 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
116 next;
117 }
118 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
119 $result->{group_name} !~ /$self->{option_results}->{filter_group}/) {
120 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_name} . "'.", debug => 1);
121 next;
122 }
123
124 $self->{ap}->{ $result->{ap_name} } = {
125 display => $result->{ap_name},
126 channels => {}
127 };
128
129 foreach my $oid (keys %$snmp_result) {
130 next if ($oid !~ /^$oid_bsnAPIfDBNoisePower\.$instance\.(\d+)\.(\d+)$/);
131 my ($slot_id, $channel_id) = ($1, $2);
132
133 my $name = "slot$slot_id:channel$channel_id";
134 if (defined($self->{option_results}->{filter_channel}) && $self->{option_results}->{filter_channel} ne '' &&
135 $name !~ /$self->{option_results}->{filter_channel}/) {
136 $self->{output}->output_add(long_msg => "skipping channel '" . $name . "': no matching filter.", debug => 1);
137 next;
138 }
139
140 $self->{ap}->{ $result->{ap_name} }->{channels}->{$name} = {
141 display => $name,
142 noise_power => $snmp_result->{$oid}
143 };
144 }
145 }
146
147 if (scalar(keys %{$self->{ap}}) <= 0) {
148 $self->{output}->add_option_msg(short_msg => "No entry found.");
149 $self->{output}->option_exit();
150 }
151 }
152
153 1;
154
155 __END__
156
157 =head1 MODE
158
159 Check AP Channel Noise.
160
161 =over 8
162
163 =item B<--filter-name>
164
165 Filter access point name (can be a regexp).
166
167 =item B<--filter-group>
168
169 Filter access point group (can be a regexp).
170
171 =item B<--filter-channel>
172
173 Filter channel (can be a regexp). Example: --filter-channel='slot0:channel3'
174
175 =item B<--warning-*> B<--critical-*>
176
177 Thresholds.
178 Can be: 'noise-power' (dBm).
179
180 =back
181
182 =cut