Debian Codegraph @

src/network/huawei/wlc/snmp/mode/listradios.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::huawei::wlc::snmp::mode::listradios;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments => {
34 "filter-name:s" => { name => 'filter_name' },
35 "filter-group:s" => { name => 'filter_group' }
36 });
37
38 return $self;
39 }
40
41 sub check_options {
42 my ($self, %options) = @_;
43 $self->SUPER::init(%options);
44 }
45
46 my $map_runstate = {
47 1 => 'up',
48 2 => 'down',
49 255 => 'invalid'
50 };
51
52 sub manage_selection {
53 my ($self, %options) = @_;
54
55 # Collecting all the relevant information user may needs when using discovery function for AP in Huawei WLC controllers.
56 # They had been select with https://support.huawei.com/enterprise/en/doc/EDOC1100306136/680fca71/huawei-wlan-ap-mib as support.
57 my $mapping = {
58 name => { oid => '.1.3.6.1.4.1.2011.6.139.16.1.2.1.3' },# hwWlanRadioInfoApName
59 frequence_type => { oid => '.1.3.6.1.4.1.2011.6.139.16.1.2.1.5' },# hwWlanRadioFreqType
60 ap_group => { oid => '.1.3.6.1.4.1.2011.6.139.16.1.2.1.55' },# hwWlanRadioApGroup
61 run_state => { oid => '.1.3.6.1.4.1.2011.6.139.16.1.2.1.6', map => $map_runstate },# hwWlanRadioRunState
62 description => { oid => '.1.3.6.1.4.1.2011.6.139.16.1.2.1.16' },# hwWlanRadioDescription
63 };
64
65 my $request = [ { oid => $mapping->{name}->{oid} } ];
66 push @$request, { oid => $mapping->{group}->{oid} }
67 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '');
68
69 push @$request, { oid => $mapping->{address}->{oid} }
70 if (defined($self->{option_results}->{filter_address}) && $self->{option_results}->{filter_address} ne '');
71
72 my $snmp_result = $options{snmp}->get_multiple_table(
73 oids => $request,
74 return_type => 1,
75 nothing_quit => 1
76 );
77
78 my $results = {};
79 # Iterate for all oids catch in snmp result above
80 foreach my $oid (keys %$snmp_result) {
81 next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);
82 my $oid_path = $1;
83
84 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $oid_path);
85
86 if (!defined($result->{name}) || $result->{name} eq '') {
87 $self->{output}->output_add(long_msg => "skipping WLC '$oid_path': cannot get a name. please set it.", debug => 1);
88 next;
89 }
90
91 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
92 $result->{name} !~ /$self->{option_results}->{filter_name}/) {
93 $self->{output}->output_add(long_msg => "skipping '" . $result->{name} . "': no matching name filter.", debug => 1);
94 next;
95 }
96
97 if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
98 $result->{ap_group} !~ /$self->{option_results}->{filter_group}/) {
99 $self->{output}->output_add(long_msg => "skipping '" . $result->{ap_group} . "': no matching group filter.", debug => 1);
100 next;
101 }
102
103 $self->{ap}->{ $result->{name} } = {
104 instance => $oid_path,
105 display => $result->{name},
106 ap_global => { display => $result->{name} },
107 interfaces => {}
108 };
109 }
110
111 $options{snmp}->load(
112 oids => [ map($_->{oid}, values(%$mapping)) ],
113 instances => [ map($_->{instance}, values %{$self->{ap}}) ],
114 instance_regexp => '^(.*)$'
115 );
116 $snmp_result = $options{snmp}->get_leef();
117
118 foreach (keys %{$self->{ap}}) {
119 my $result = $options{snmp}->map_instance(mapping =>
120 $mapping, results =>
121 $snmp_result,
122 instance =>
123 $self->{ap}->{$_}->{instance});
124
125 $results->{$self->{ap}->{$_}->{instance}} = {
126 name => $result->{name},
127 frequence_type => $result->{frequence_type},
128 run_state => $result->{run_state},
129 description => $result->{description},
130 ap_group => $result->{ap_group}
131 };
132 }
133
134 return $results;
135 }
136
137 sub run {
138 my ($self, %options) = @_;
139
140 my $results = $self->manage_selection(snmp => $options{snmp});
141 foreach my $oid_path (sort keys %$results) {
142 $self->{output}->output_add(
143 long_msg => sprintf(
144 '[oid_path: %s] [name: %s] [frequence_type: %s] [run_state: %s] [description: %s] [ap_group: %s]',
145 $oid_path,
146 $results->{$oid_path}->{name},
147 $results->{$oid_path}->{frequence_type},
148 $results->{$oid_path}->{run_state},
149 $results->{$oid_path}->{description},
150 $results->{$oid_path}->{ap_group}
151 )
152 );
153 }
154
155 $self->{output}->output_add(
156 severity => 'OK',
157 short_msg => 'List aps'
158 );
159 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
160 $self->{output}->exit();
161 }
162
163 sub disco_format {
164 my ($self, %options) = @_;
165
166 $self->{output}->add_disco_format(elements =>
167 [ 'name', 'frequence_type', 'run_state', 'description', 'ap_group' ]);
168 }
169
170 sub disco_show {
171 my ($self, %options) = @_;
172
173 my $results = $self->manage_selection(snmp => $options{snmp});
174 foreach my $oid_path (sort keys %$results) {
175 $self->{output}->add_disco_entry(
176 name => $results->{$oid_path}->{name},
177 frequence_type => $results->{$oid_path}->{frequence_type},
178 run_state => $results->{$oid_path}->{run_state},
179 description => $results->{$oid_path}->{description},
180 ap_group => $results->{$oid_path}->{ap_group}
181 );
182 }
183 }
184
185 1;
186
187 __END__
188
189 =head1 MODE
190
191 List radios.
192
193 =over 8
194
195 =item B<--filter-name>
196
197 Display AP radios matching the filter.
198
199 =item B<--filter-group>
200
201 Display AP radios matching the filter.
202
203 =back
204
205 =cut