enhance snampmirrorlag netapp

This commit is contained in:
garnier-quentin 2019-10-07 14:52:46 +02:00
parent 626a0b84e1
commit 53d360437e
1 changed files with 101 additions and 51 deletions

View File

@ -29,7 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_calc { sub custom_status_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0; return 0;
} }
@ -43,9 +43,9 @@ sub set_counters {
$self->{maps_counters}->{snapmirror} = [ $self->{maps_counters}->{snapmirror} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'state' }, { name => 'display' } ],
output_template => "status is '%s'", output_template => "state is '%s'",
output_use => 'status', output_use => 'state',
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold,
@ -75,10 +75,11 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"filter-status:s" => { name => 'filter_status' }, 'filter-name:s' => { name => 'filter_name' },
"unknown-status:s" => { name => 'unknown_status', default => '' }, 'filter-status:s' => { name => 'filter_status' },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /quiesced/i' }, 'unknown-status:s' => { name => 'unknown_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /unknown|brokenOff|uninitialized/i' }, 'warning-status:s' => { name => 'warning_status', default => '%{state} =~ /quiesced/i' },
'critical-status:s' => { name => 'critical_status', default => '%{state} =~ /unknown|brokenOff|uninitialized/i' },
}); });
return $self; return $self;
@ -91,62 +92,55 @@ sub check_options {
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
} }
sub manage_selection { sub check_snapmirror {
my ($self, %options) = @_; my ($self, %options) = @_;
my $oid_snapmirrorOn = '.1.3.6.1.4.1.789.1.9.1.0'; my $oid_snapmirrorOn = '.1.3.6.1.4.1.789.1.9.1.0';
my $oid_snapmirrorSrc = '.1.3.6.1.4.1.789.1.9.20.1.2'; my $oid_snapmirrorSrc = '.1.3.6.1.4.1.789.1.9.20.1.2';
my $result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]); my $snmp_result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]);
if (!defined($result->{$oid_snapmirrorOn}) || $result->{$oid_snapmirrorOn} != 2) { return if (!defined($snmp_result->{$oid_snapmirrorOn}));
$self->{output}->add_option_msg(short_msg => "Snapmirror is not turned on.");
if ($snmp_result->{$oid_snapmirrorOn} != 2) {
$self->{output}->add_option_msg(short_msg => "snapmirror is not turned on.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my $id_selected = []; my $id_selected = [];
my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorSrc, nothing_quit => 1); my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorSrc, nothing_quit => 1);
foreach my $oid (keys %{$snmp_result_name}) { foreach my $oid (keys %$snmp_result_name) {
next if ($oid !~ /\.([0-9]+)$/); next if ($oid !~ /\.([0-9]+)$/);
my $instance = $1; my $instance = $1;
# Get all without a name if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
if (!defined($self->{option_results}->{name})) { $snmp_result_name->{$oid} !~ /$self->{option_results}->{filter_name}/) {
push @{$id_selected}, $instance; $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid} . "': no matching filter.", debug => 1);
next; next;
} }
if (!defined($self->{option_results}->{use_regexp}) && $snmp_result_name->{$oid} eq $self->{option_results}->{name}) { push @$id_selected, $instance;
push @{$id_selected}, $instance;
}
if (defined($self->{option_results}->{use_regexp}) && $snmp_result_name->{$oid} =~ /$self->{option_results}->{name}/) {
push @{$id_selected}, $instance;
}
} }
if (scalar(@{$id_selected}) <= 0) { if (scalar(@$id_selected) <= 0) {
$self->{output}->add_option_msg(short_msg => "No snapmirrors found for name '" . $self->{option_results}->{name} . "'."); $self->{output}->add_option_msg(short_msg => "No snapmirrors found for filter '" . $self->{option_results}->{filter_name} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my %map_state = ( my $map_state = {
1 => 'uninitialized', 1 => 'uninitialized', 2 => 'snapmirrored',
2 => 'snapmirrored', 3 => 'brokenOff', 4 => 'quiesced',
3 => 'brokenOff', 5 => 'source', 6 => 'unknown',
4 => 'quiesced', };
5 => 'source',
6 => 'unknown',
);
my $mapping = { my $mapping = {
snapmirrorState => { oid => '.1.3.6.1.4.1.789.1.9.20.1.5', map => \%map_state }, snapmirrorState => { oid => '.1.3.6.1.4.1.789.1.9.20.1.5', map => $map_state },
snapmirrorLag => { oid => '.1.3.6.1.4.1.789.1.9.20.1.6' }, snapmirrorLag => { oid => '.1.3.6.1.4.1.789.1.9.20.1.6' },
}; };
$options{snmp}->load(oids => [$mapping->{snapmirrorState}->{oid}, $mapping->{snapmirrorLag}->{oid}], instances => $id_selected); $options{snmp}->load(oids => [$mapping->{snapmirrorState}->{oid}, $mapping->{snapmirrorLag}->{oid}], instances => $id_selected);
my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
$self->{snapmirror} = {}; $self->{snapmirror} = {};
foreach (@$id_selected) {
foreach (@{$id_selected}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); 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 '' && if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' &&
$result->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) { $result->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) {
@ -156,11 +150,71 @@ sub manage_selection {
$self->{snapmirror}->{$_} = { $self->{snapmirror}->{$_} = {
display => $snmp_result_name->{$oid_snapmirrorSrc . '.' . $_}, display => $snmp_result_name->{$oid_snapmirrorSrc . '.' . $_},
status => $result->{snapmirrorState}, state => $result->{snapmirrorState},
lag => int($result->{snapmirrorLag} / 100), lag => int($result->{snapmirrorLag} / 100),
}; };
} }
}
sub check_sm {
my ($self, %options) = @_;
my $oid_snapmirrorRelSrcPath = '.1.3.6.1.4.1.789.1.29.1.1.2';
my $id_selected = [];
my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorRelSrcPath, nothing_quit => 1);
foreach my $oid (keys %$snmp_result_name) {
next if ($oid !~ /\.([0-9]+)$/);
my $instance = $1;
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 snapmirrors found for filter '" . $self->{option_results}->{filter_name} . "'.");
$self->{output}->option_exit();
}
my $map_state = {
0 => 'uninitialized', 1 => 'snapmirrored', 2 => 'brokenOff',
};
my $mapping = {
snapmirrorRelState => { oid => '.1.3.6.1.4.1.789.1.29.1.1.6', map => $map_state },
snapmirrorRelLag => { oid => '.1.3.6.1.4.1.789.1.29.1.1.7' },
};
$options{snmp}->load(oids => [$mapping->{snapmirrorRelState}->{oid}, $mapping->{snapmirrorRelLag}->{oid}], instances => $id_selected);
my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
$self->{snapmirror} = {};
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->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) {
$self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid_snapmirrorRelSrcPath . '.' . $_} . "': no matching filter.", debug => 1);
next;
}
$self->{snapmirror}->{$_} = {
display => $snmp_result_name->{$oid_snapmirrorRelSrcPath . '.' . $_},
state => $result->{snapmirrorRelState},
lag => int($result->{snapmirrorRelLag} / 100),
};
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->check_snapmirror(%options);
$self->check_sm(%options);
if (scalar(keys %{$self->{snapmirror}}) <= 0) { if (scalar(keys %{$self->{snapmirror}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No snapmirrors found."); $self->{output}->add_option_msg(short_msg => "No snapmirrors found.");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -177,13 +231,9 @@ Check snapmirrors status and lag.
=over 8 =over 8
=item B<--name> =item B<--filter-name>
Set the snapmirror name. Filter the snapmirror name (can be a regexp).
=item B<--regexp>
Allows to use regexp to filter snampmirror name (with option --name).
=item B<--filter-status> =item B<--filter-status>
@ -197,17 +247,17 @@ Example: --filter-counters='^status$'
=item B<--unknown-status> =item B<--unknown-status>
Set warning threshold for status (Default: ''). Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{display} Can used special variables like: %{state}, %{display}
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status (Default: '%{status} =~ /quiesced/i'). Set warning threshold for status (Default: '%{state} =~ /quiesced/i').
Can used special variables like: %{status}, %{display} Can used special variables like: %{state}, %{display}
=item B<--critical-status> =item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /unknown|brokenOff|uninitialized/i'). Set critical threshold for status (Default: '%{state} =~ /unknown|brokenOff|uninitialized/i').
Can used special variables like: %{status}, %{display} Can used special variables like: %{state}, %{display}
=item B<--warning-lag> =item B<--warning-lag>