| 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 storage::wd::nas::snmp::mode::listvolumes; |
| 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 |
}); |
| 35 |
|
| 36 |
return $self; |
| 37 |
} |
| 38 |
|
| 39 |
sub check_options { |
| 40 |
my ($self, %options) = @_; |
| 41 |
$self->SUPER::init(%options); |
| 42 |
} |
| 43 |
|
| 44 |
sub manage_selection { |
| 45 |
my ($self, %options) = @_; |
| 46 |
|
| 47 |
my $nas = { |
| 48 |
ex2 => { |
| 49 |
volumeTable => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1', |
| 50 |
volume => { |
| 51 |
name => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1.2' }, |
| 52 |
type => { oid => '.1.3.6.1.4.1.5127.1.1.1.2.1.9.1.3' } |
| 53 |
} |
| 54 |
}, |
| 55 |
ex2ultra => { |
| 56 |
volumeTable => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1', |
| 57 |
volume => { |
| 58 |
name => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1.2' }, |
| 59 |
type => { oid => '.1.3.6.1.4.1.5127.1.1.1.8.1.9.1.3' } |
| 60 |
} |
| 61 |
}, |
| 62 |
ex4100 => { |
| 63 |
volumeTable => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1', |
| 64 |
volume => { |
| 65 |
name => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1.2' }, |
| 66 |
type => { oid => '.1.3.6.1.4.1.5127.1.1.1.6.1.9.1.3' } |
| 67 |
} |
| 68 |
}, |
| 69 |
pr2100 => { |
| 70 |
volumeTable => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1', |
| 71 |
volume => { |
| 72 |
name => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1.2' }, |
| 73 |
type => { oid => '.1.3.6.1.4.1.5127.1.1.1.9.1.9.1.3' } |
| 74 |
} |
| 75 |
}, |
| 76 |
pr4100 => { |
| 77 |
volumeTable => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1', |
| 78 |
volume => { |
| 79 |
name => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1.2' }, |
| 80 |
type => { oid => '.1.3.6.1.4.1.5127.1.1.1.10.1.9.1.3' } |
| 81 |
} |
| 82 |
} |
| 83 |
}; |
| 84 |
|
| 85 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 86 |
oids => [ |
| 87 |
{ oid => $nas->{ex2}->{volumeTable} }, |
| 88 |
{ oid => $nas->{ex2ultra}->{volumeTable} }, |
| 89 |
{ oid => $nas->{ex4100}->{volumeTable} }, |
| 90 |
{ oid => $nas->{pr2100}->{volumeTable} }, |
| 91 |
{ oid => $nas->{pr4100}->{volumeTable} } |
| 92 |
] |
| 93 |
); |
| 94 |
|
| 95 |
my $volumes = {}; |
| 96 |
foreach my $type (keys %$nas) { |
| 97 |
next if (scalar(keys %{$snmp_result->{ $nas->{$type}->{volumeTable} }}) <= 0); |
| 98 |
foreach (keys %{$snmp_result->{ $nas->{$type}->{volumeTable} }}) { |
| 99 |
next if (! /^$nas->{$type}->{volume}->{name}->{oid}\.(\d+)$/); |
| 100 |
|
| 101 |
$volumes->{$1} = $options{snmp}->map_instance(mapping => $nas->{$type}->{volume}, results => $snmp_result->{ $nas->{$type}->{volumeTable} }, instance => $1); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
return $volumes; |
| 106 |
} |
| 107 |
|
| 108 |
sub run { |
| 109 |
my ($self, %options) = @_; |
| 110 |
|
| 111 |
my $volumes = $self->manage_selection(%options); |
| 112 |
foreach (sort keys %$volumes) { |
| 113 |
$self->{output}->output_add( |
| 114 |
long_msg => sprintf( |
| 115 |
'[name: %s] [type: %s]', |
| 116 |
$volumes->{$_}->{name}, |
| 117 |
$volumes->{$_}->{type} |
| 118 |
) |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
$self->{output}->output_add( |
| 123 |
severity => 'OK', |
| 124 |
short_msg => 'List volumes:' |
| 125 |
); |
| 126 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 127 |
$self->{output}->exit(); |
| 128 |
} |
| 129 |
|
| 130 |
sub disco_format { |
| 131 |
my ($self, %options) = @_; |
| 132 |
|
| 133 |
$self->{output}->add_disco_format(elements => ['name', 'type']); |
| 134 |
} |
| 135 |
|
| 136 |
sub disco_show { |
| 137 |
my ($self, %options) = @_; |
| 138 |
|
| 139 |
my $volumes = $self->manage_selection(%options); |
| 140 |
foreach (sort keys %$volumes) { |
| 141 |
$self->{output}->add_disco_entry( |
| 142 |
%{$volumes->{$_}} |
| 143 |
); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
1; |
| 148 |
|
| 149 |
__END__ |
| 150 |
|
| 151 |
=head1 MODE |
| 152 |
|
| 153 |
List volumes. |
| 154 |
|
| 155 |
=over 8 |
| 156 |
|
| 157 |
=back |
| 158 |
|
| 159 |
=cut |