This commit is contained in:
parent
3f1032660d
commit
ebeac3d25d
|
@ -20,13 +20,84 @@
|
|||
|
||||
package storage::netapp::snmp::mode::volumeoptions;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
my $oid_volName = '.1.3.6.1.4.1.789.1.5.8.1.2';
|
||||
my $oid_volOptions = '.1.3.6.1.4.1.789.1.5.8.1.7';
|
||||
sub custom_options_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $status = catalog_status_threshold($self, %options);
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{instance_mode}->{global}->{failed}++;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_options_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{options} = $options{new_datas}->{$self->{instance} . '_options'};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volume options are ok' },
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{volume} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'status' }, { name => 'display' } ],
|
||||
output_template => "status is '%s'",
|
||||
output_use => 'status',
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
}
|
||||
},
|
||||
{ label => 'options', threshold => 0, set => {
|
||||
key_values => [ { name => 'options' }, { name => 'display' } ],
|
||||
output_template => "options: '%s'",
|
||||
output_use => 'options',
|
||||
closure_custom_calc => $self->can('custom_options_calc'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => $self->can('custom_options_threshold'),
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'failed', display_ok => 0, set => {
|
||||
key_values => [ { name => 'failed' } ],
|
||||
output_template => 'Failed: %s',
|
||||
perfdatas => [
|
||||
{ label => 'failed', value => 'failed_absolute', template => '%s', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_volume_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Volume '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -34,104 +105,82 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warn" => { name => 'warn' },
|
||||
"crit" => { name => 'crit' },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"option:s" => { name => 'option' },
|
||||
});
|
||||
$self->{volume_id_selected} = [];
|
||||
$self->{status} = 'OK';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"filter-status:s" => { name => 'filter_status' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
"unknown-options:s" => { name => 'unknown_options', default => '' },
|
||||
"warning-options:s" => { name => 'warning_options', default => '' },
|
||||
"critical-options:s" => { name => 'critical_options', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (defined($self->{option_results}->{warn})) {
|
||||
$self->{status} = 'WARNING';
|
||||
}
|
||||
if (defined($self->{option_results}->{crit})) {
|
||||
$self->{status} = 'CRITICAL';
|
||||
}
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_options', 'critical_options', 'unknown_options',
|
||||
'warning_status', 'critical_status', 'unknown_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_names} = $self->{snmp}->get_table(oid => $oid_volName, nothing_quit => 1);
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result_names}})) {
|
||||
my $oid_volName = '.1.3.6.1.4.1.789.1.5.8.1.2';
|
||||
my $id_selected = [];
|
||||
my $snmp_result_name = $options{snmp}->get_table(oid => $oid_volName, nothing_quit => 1);
|
||||
foreach my $oid (keys %{$snmp_result_name}) {
|
||||
next if ($oid !~ /\.([0-9]+)$/);
|
||||
my $instance = $1;
|
||||
|
||||
# Get all without a name
|
||||
if (!defined($self->{option_results}->{name})) {
|
||||
push @{$self->{volume_id_selected}}, $instance;
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$snmp_result_name->{oid} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{oid} . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
push @{$id_selected}, $instance;
|
||||
}
|
||||
|
||||
if (scalar(@{$id_selected}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No volume found for name '" . $self->{option_results}->{filter_name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $mapping = {
|
||||
volState => { oid => '.1.3.6.1.4.1.789.1.5.8.1.5' },
|
||||
volOptions => { oid => '.1.3.6.1.4.1.789.1.5.8.1.7' },
|
||||
};
|
||||
|
||||
$options{snmp}->load(oids => [$mapping->{volState}->{oid}, $mapping->{volOptions}->{oid}], instances => $id_selected);
|
||||
my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
$self->{global} = { failed => 0 };
|
||||
$self->{volumes} = {};
|
||||
foreach (@{$id_selected}) {
|
||||
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
|
||||
if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
|
||||
$result->{volState} !~ /$self->{option_results}->{filter_status}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid_volName . '.' . $_} . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) {
|
||||
push @{$self->{volume_id_selected}}, $instance;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) {
|
||||
push @{$self->{volume_id_selected}}, $instance;
|
||||
}
|
||||
$self->{volumes}->{$_} = {
|
||||
display => $snmp_result_name->{$oid_volName . '.' . $_},
|
||||
status => $result->{volState},
|
||||
options => $result->{volOptions},
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{volume_id_selected}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No volume found for name '" . $self->{option_results}->{name} . "'.");
|
||||
|
||||
if (scalar(keys %{$self->{volumes}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No volume found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
$self->manage_selection();
|
||||
$self->{snmp}->load(oids => [$oid_volOptions], instances => $self->{volume_id_selected});
|
||||
my $result = $self->{snmp}->get_leef();
|
||||
|
||||
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All volume options are ok.');
|
||||
}
|
||||
|
||||
my $failed = 0;
|
||||
foreach my $instance (sort @{$self->{volume_id_selected}}) {
|
||||
my $name = $self->{result_names}->{$oid_volName . '.' . $instance};
|
||||
my $option = $result->{$oid_volOptions . '.' . $instance};
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Volume '%s' options: %s", $name, $option));
|
||||
|
||||
my $status;
|
||||
if (defined($self->{option_results}->{option}) && $option !~ /$self->{option_results}->{option}/) {
|
||||
$status = $self->{status};
|
||||
$failed++;
|
||||
}
|
||||
|
||||
# Can be 'ok' if we don't set a threshold option '--warn', '--crit'
|
||||
if (defined($status)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("Volume '%s' pattern '%s' is not matching", $name, $self->{option_results}->{option}));
|
||||
} elsif (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => sprintf("Volume '%s' option is ok", $name));
|
||||
}
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'failed',
|
||||
value => $failed,
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -142,27 +191,45 @@ Check options from volumes.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--warn>
|
||||
=item B<--filter-name>
|
||||
|
||||
Return Warning (need '--option' also).
|
||||
Filter on volume name (can be a regexp).
|
||||
|
||||
=item B<--critical>
|
||||
=item B<--filter-status>
|
||||
|
||||
Return Critical (need '--option' also).
|
||||
Filter on volume status (can be a regexp).
|
||||
|
||||
=item B<--name>
|
||||
=item B<--unknown-status>
|
||||
|
||||
Set the volume name.
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{status}, %{display}
|
||||
|
||||
=item B<--regexp>
|
||||
=item B<--warning-status>
|
||||
|
||||
Allows to use regexp to filter volume name (with option --name).
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{status}, %{display}
|
||||
|
||||
=item B<--option>
|
||||
=item B<--critical-status>
|
||||
|
||||
Options to check (Example: if 'nosnap=off' not maching, returns Warning or Critical for the volume).
|
||||
Set critical threshold for status (Default: '').
|
||||
Can used special variables like: %{status}, %{display}
|
||||
|
||||
=item B<--unknown-options>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{options}, %{display}
|
||||
|
||||
=item B<--warning-options>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{options}, %{display}
|
||||
|
||||
=item B<--critical-options>
|
||||
|
||||
Set critical threshold for status (Default: '').
|
||||
Can used special variables like: %{options}, %{display}
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue