Debian Codegraph @

src/centreon/common/airespace/snmp/mode/discovery.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::discovery;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27 use JSON::XS;
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
32 bless $self, $class;
33
34 $options{options}->add_options(arguments => {
35 'filter-admin-down' => { name => 'filter_admin_down' },
36 'prettify' => { name => 'prettify' }
37 });
38
39 return $self;
40 }
41
42 sub check_options {
43 my ($self, %options) = @_;
44 $self->SUPER::init(%options);
45 }
46
47 my $map_admin_status = {
48 1 => 'enable',
49 2 => 'disable'
50 };
51 my $map_operation_status = {
52 1 => 'associated',
53 2 => 'disassociating',
54 3 => 'downloading'
55 };
56
57 my $mapping = {
58 ap_name => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.3' }, # bsnAPName
59 ap_location => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.4' }, # bsnAPLocation
60 ap_opstatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.6', map => $map_operation_status }, # bsnAPOperationStatus
61 ap_model => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.16' }, # bsnAPModel
62 ap_ipaddr => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.19' }, # bsnApIpAddress
63 ap_admstatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.37', map => $map_admin_status } # bsnAPAdminStatus
64 };
65
66 sub run {
67 my ($self, %options) = @_;
68
69 my @disco_data;
70 my $disco_stats;
71
72 $disco_stats->{start_time} = time();
73
74 my $request = [
75 { oid => $mapping->{ap_name}->{oid} },
76 { oid => $mapping->{ap_location}->{oid} },
77 { oid => $mapping->{ap_opstatus}->{oid} },
78 { oid => $mapping->{ap_model}->{oid} },
79 { oid => $mapping->{ap_ipaddr}->{oid} },
80 { oid => $mapping->{ap_admstatus}->{oid} }
81 ];
82 my $snmp_result = $options{snmp}->get_multiple_table(
83 oids => $request,
84 return_type => 1,
85 nothing_quit => 1
86 );
87
88 foreach (keys %$snmp_result) {
89 next if (! /^$mapping->{ap_name}->{oid}\.(.*)/);
90 my $instance = $1;
91
92 my $result = $options{snmp}->map_instance(
93 mapping => $mapping,
94 results => $snmp_result,
95 instance => $instance);
96
97 next if (defined($self->{option_results}->{filter_admin_down}) && $result->{ap_admstatus} eq 'disable');
98
99 my $ap = {
100 name => $result->{ap_name},
101 instance => $instance,
102 location => $result->{ap_location},
103 model => $result->{ap_model},
104 ip => $result->{ap_ipaddr},
105 admstatus => $result->{ap_admstatus},
106 opstatus => $result->{ap_opstatus}
107 };
108
109 push @disco_data, $ap;
110 }
111
112 $disco_stats->{end_time} = time();
113 $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
114 $disco_stats->{discovered_items} = @disco_data;
115 $disco_stats->{results} = \@disco_data;
116
117 my $encoded_data;
118 eval {
119 if (defined($self->{option_results}->{prettify})) {
120 $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats);
121 } else {
122 $encoded_data = JSON::XS->new->utf8->encode($disco_stats);
123 }
124 };
125 if ($@) {
126 $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
127 }
128
129 $self->{output}->output_add(short_msg => $encoded_data);
130 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
131 $self->{output}->exit();
132 }
133
134 1;
135
136 __END__
137
138 =head1 MODE
139
140 Cisco WLC/Airspace AP discovery.
141
142 Note: When the IP Address is 0, that means the switch is operating in layer2 mode
143 Ref: https://cric.grenoble.cnrs.fr/Administrateurs/Outils/MIBS/?oid=1.3.6.1.4.1.14179.2.2.1.1.19
144
145 =over 8
146
147 =item B<--prettify>
148
149 Prettify JSON output.
150
151 =item B<--filter-admin-down>
152
153 Exclude administratively down access points from the discovery result
154
155 =back
156
157 =cut