| 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::aruba::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 |
"prettify" => { name => 'prettify' }, |
| 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_status = ( |
| 47 |
1 => 'up', 2 => 'down' |
| 48 |
); |
| 49 |
|
| 50 |
my $oid_wlsxWlanAPTable = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1'; |
| 51 |
|
| 52 |
my $mapping = { |
| 53 |
wlanAPIpAddress => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.2' }, |
| 54 |
wlanAPName => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3' }, |
| 55 |
wlanAPGroupName=> { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.4' }, |
| 56 |
wlanAPUpTime => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.12' }, |
| 57 |
wlanAPLocation => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.14' }, |
| 58 |
wlanAPStatus => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.20', map => \%map_status }, |
| 59 |
wlanAPNumBootstraps => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.21' }, |
| 60 |
wlanAPNumReboots => { oid => '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.22' }, |
| 61 |
}; |
| 62 |
|
| 63 |
sub run { |
| 64 |
my ($self, %options) = @_; |
| 65 |
|
| 66 |
my @disco_data; |
| 67 |
my $disco_stats; |
| 68 |
|
| 69 |
$disco_stats->{start_time} = time(); |
| 70 |
|
| 71 |
my $snmp_result = $options{snmp}->get_table( |
| 72 |
oid => $oid_wlsxWlanAPTable, |
| 73 |
start => $mapping->{wlanAPIpAddress}->{oid}, |
| 74 |
end => $mapping->{wlanAPNumReboots}->{oid}, |
| 75 |
nothing_quit => 1 |
| 76 |
); |
| 77 |
|
| 78 |
foreach my $oid (keys %{$snmp_result}) { |
| 79 |
next if ($oid !~ /^$mapping->{wlanAPIpAddress}->{oid}\.(.*)/); |
| 80 |
my $instance = $1; |
| 81 |
|
| 82 |
my $result = $options{snmp}->map_instance( |
| 83 |
mapping => $mapping, |
| 84 |
results => $snmp_result, |
| 85 |
instance => $instance |
| 86 |
); |
| 87 |
|
| 88 |
my %ap; |
| 89 |
$ap{name} = $result->{wlanAPName}; |
| 90 |
$ap{ip} = $result->{wlanAPIpAddress}; |
| 91 |
$ap{group} = $result->{wlanAPGroupName}; |
| 92 |
$ap{location} = $result->{wlanAPLocation}; |
| 93 |
$ap{status} = $result->{wlanAPStatus}; |
| 94 |
$ap{type} = "ap"; |
| 95 |
|
| 96 |
push @disco_data, \%ap; |
| 97 |
} |
| 98 |
|
| 99 |
$disco_stats->{end_time} = time(); |
| 100 |
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; |
| 101 |
$disco_stats->{discovered_items} = @disco_data; |
| 102 |
$disco_stats->{results} = \@disco_data; |
| 103 |
|
| 104 |
my $encoded_data; |
| 105 |
eval { |
| 106 |
if (defined($self->{option_results}->{prettify})) { |
| 107 |
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); |
| 108 |
} else { |
| 109 |
$encoded_data = JSON::XS->new->utf8->encode($disco_stats); |
| 110 |
} |
| 111 |
}; |
| 112 |
if ($@) { |
| 113 |
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; |
| 114 |
} |
| 115 |
|
| 116 |
$self->{output}->output_add(short_msg => $encoded_data); |
| 117 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); |
| 118 |
$self->{output}->exit(); |
| 119 |
} |
| 120 |
|
| 121 |
1; |
| 122 |
|
| 123 |
__END__ |
| 124 |
|
| 125 |
=head1 MODE |
| 126 |
|
| 127 |
Resources discovery. |
| 128 |
|
| 129 |
=over 8 |
| 130 |
|
| 131 |
=item B<--prettify> |
| 132 |
|
| 133 |
Prettify JSON output. |
| 134 |
|
| 135 |
=back |
| 136 |
|
| 137 |
=cut |