| 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 hardware::sensors::rittal::cmc3::snmp::mode::listdevices; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
my $map_status = { |
| 29 |
1 => 'Device not available', |
| 30 |
2 => 'OK', |
| 31 |
3 => 'Device detected, confirmation required', |
| 32 |
4 => 'Device lost (disconnected), confirmation required', |
| 33 |
5 => 'Device changed', |
| 34 |
6 => 'Error', |
| 35 |
7 => 'Firmware update pending', |
| 36 |
8 => 'Firmware update runnning' |
| 37 |
}; |
| 38 |
|
| 39 |
my $mapping = { |
| 40 |
dev_name => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.2' }, |
| 41 |
dev_alias => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.3' }, |
| 42 |
dev_status => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.6', map => $map_status }, |
| 43 |
dev_status_text => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.19' } |
| 44 |
}; |
| 45 |
|
| 46 |
sub new { |
| 47 |
my ($class, %options) = @_; |
| 48 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 49 |
bless $self, $class; |
| 50 |
|
| 51 |
$options{options}->add_options( |
| 52 |
arguments => |
| 53 |
{ |
| 54 |
'filter-name:s' => { name => 'filter_name' }, |
| 55 |
'filter-alias:s' => { name => 'filter_alias' } |
| 56 |
} |
| 57 |
); |
| 58 |
|
| 59 |
return $self; |
| 60 |
} |
| 61 |
|
| 62 |
sub check_options { |
| 63 |
my ($self, %options) = @_; |
| 64 |
$self->SUPER::init(%options); |
| 65 |
} |
| 66 |
|
| 67 |
sub manage_selection { |
| 68 |
my ($self, %options) = @_; |
| 69 |
|
| 70 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 71 |
oids => [ |
| 72 |
{ oid => $mapping->{dev_name}->{oid} }, |
| 73 |
{ oid => $mapping->{dev_alias}->{oid} }, |
| 74 |
{ oid => $mapping->{dev_status}->{oid} }, |
| 75 |
{ oid => $mapping->{dev_status_text}->{oid} } |
| 76 |
], |
| 77 |
return_type => 1, |
| 78 |
nothing_quit => 1 |
| 79 |
); |
| 80 |
|
| 81 |
my $results = {}; |
| 82 |
foreach my $oid (keys %{$snmp_result}) { |
| 83 |
next if ($oid !~ /^$mapping->{dev_name}->{oid}\.(.*)$/); |
| 84 |
my $instance = $1; |
| 85 |
my $data = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 86 |
|
| 87 |
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 88 |
$data->{dev_name} !~ /$self->{option_results}->{filter_name}/); |
| 89 |
next if (defined($self->{option_results}->{filter_alias}) && $self->{option_results}->{filter_alias} ne '' && |
| 90 |
$data->{dev_alias} !~ /$self->{option_results}->{filter_alias}/); |
| 91 |
|
| 92 |
$results->{$instance} = { |
| 93 |
index => $instance, |
| 94 |
name => $data->{dev_name}, |
| 95 |
alias => $data->{dev_alias}, |
| 96 |
status => $data->{dev_status}, |
| 97 |
statusText => $data->{dev_status_text} |
| 98 |
}; |
| 99 |
} |
| 100 |
|
| 101 |
return $results; |
| 102 |
} |
| 103 |
|
| 104 |
sub run { |
| 105 |
my ($self, %options) = @_; |
| 106 |
|
| 107 |
my $results = $self->manage_selection(%options); |
| 108 |
foreach my $instance (sort keys %$results) { |
| 109 |
$self->{output}->output_add(long_msg => sprintf( |
| 110 |
"[index: %d] [name: %s] [alias: %s] [status: %s] [statusText: '%s']", |
| 111 |
$results->{$instance}->{index}, |
| 112 |
$results->{$instance}->{name}, |
| 113 |
$results->{$instance}->{alias}, |
| 114 |
$results->{$instance}->{status}, |
| 115 |
$results->{$instance}->{statusText} |
| 116 |
)); |
| 117 |
} |
| 118 |
|
| 119 |
$self->{output}->output_add( |
| 120 |
severity => 'OK', |
| 121 |
short_msg => 'Devices list:' |
| 122 |
); |
| 123 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 124 |
$self->{output}->exit(); |
| 125 |
} |
| 126 |
|
| 127 |
sub disco_format { |
| 128 |
my ($self, %options) = @_; |
| 129 |
|
| 130 |
$self->{output}->add_disco_format(elements => [ 'index', 'name', 'alias', 'status', 'statusText' ]); |
| 131 |
} |
| 132 |
|
| 133 |
sub disco_show { |
| 134 |
my ($self, %options) = @_; |
| 135 |
|
| 136 |
my $results = $self->manage_selection(%options); |
| 137 |
foreach my $instance (sort keys %$results) { |
| 138 |
$self->{output}->add_disco_entry(%{$results->{$instance}}); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
1; |
| 143 |
|
| 144 |
__END__ |
| 145 |
|
| 146 |
=head1 MODE |
| 147 |
|
| 148 |
List devices |
| 149 |
|
| 150 |
=over 8 |
| 151 |
|
| 152 |
=item B<--filter-name> |
| 153 |
|
| 154 |
Filter device name (can be a regexp). |
| 155 |
|
| 156 |
=item B<--filter-alias> |
| 157 |
|
| 158 |
Filter devices alias (can be a regexp). |
| 159 |
|
| 160 |
=cut |