From 53d360437eeb29b6ae9d7351034ce8ee183b6879 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 7 Oct 2019 14:52:46 +0200 Subject: [PATCH] enhance snampmirrorlag netapp --- storage/netapp/snmp/mode/snapmirrorlag.pm | 152 ++++++++++++++-------- 1 file changed, 101 insertions(+), 51 deletions(-) diff --git a/storage/netapp/snmp/mode/snapmirrorlag.pm b/storage/netapp/snmp/mode/snapmirrorlag.pm index 0c1d7291f..1b8bed064 100644 --- a/storage/netapp/snmp/mode/snapmirrorlag.pm +++ b/storage/netapp/snmp/mode/snapmirrorlag.pm @@ -29,7 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_calc { 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'}; return 0; } @@ -43,9 +43,9 @@ sub set_counters { $self->{maps_counters}->{snapmirror} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'status' }, { name => 'display' } ], - output_template => "status is '%s'", - output_use => 'status', + key_values => [ { name => 'state' }, { name => 'display' } ], + output_template => "state is '%s'", + output_use => 'state', closure_custom_calc => $self->can('custom_status_calc'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold, @@ -75,10 +75,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-status:s" => { name => 'filter_status' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /quiesced/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /unknown|brokenOff|uninitialized/i' }, + '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 => '%{state} =~ /quiesced/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} =~ /unknown|brokenOff|uninitialized/i' }, }); return $self; @@ -91,62 +92,55 @@ sub check_options { $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub manage_selection { +sub check_snapmirror { my ($self, %options) = @_; 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 $result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]); - if (!defined($result->{$oid_snapmirrorOn}) || $result->{$oid_snapmirrorOn} != 2) { - $self->{output}->add_option_msg(short_msg => "Snapmirror is not turned on."); + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]); + return if (!defined($snmp_result->{$oid_snapmirrorOn})); + + if ($snmp_result->{$oid_snapmirrorOn} != 2) { + $self->{output}->add_option_msg(short_msg => "snapmirror is not turned on."); $self->{output}->option_exit(); } my $id_selected = []; 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]+)$/); my $instance = $1; - - # Get all without a name - if (!defined($self->{option_results}->{name})) { - push @{$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; } - - if (!defined($self->{option_results}->{use_regexp}) && $snmp_result_name->{$oid} eq $self->{option_results}->{name}) { - push @{$id_selected}, $instance; - } - if (defined($self->{option_results}->{use_regexp}) && $snmp_result_name->{$oid} =~ /$self->{option_results}->{name}/) { - push @{$id_selected}, $instance; - } + + push @$id_selected, $instance; } - if (scalar(@{$id_selected}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No snapmirrors found for name '" . $self->{option_results}->{name} . "'."); + 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 = ( - 1 => 'uninitialized', - 2 => 'snapmirrored', - 3 => 'brokenOff', - 4 => 'quiesced', - 5 => 'source', - 6 => 'unknown', - ); + my $map_state = { + 1 => 'uninitialized', 2 => 'snapmirrored', + 3 => 'brokenOff', 4 => 'quiesced', + 5 => 'source', 6 => 'unknown', + }; 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' }, }; - + $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} = {}; - - foreach (@{$id_selected}) { + 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}/) { @@ -156,11 +150,71 @@ sub manage_selection { $self->{snapmirror}->{$_} = { display => $snmp_result_name->{$oid_snapmirrorSrc . '.' . $_}, - status => $result->{snapmirrorState}, + state => $result->{snapmirrorState}, 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) { $self->{output}->add_option_msg(short_msg => "No snapmirrors found."); $self->{output}->option_exit(); @@ -177,13 +231,9 @@ Check snapmirrors status and lag. =over 8 -=item B<--name> +=item B<--filter-name> -Set the snapmirror name. - -=item B<--regexp> - -Allows to use regexp to filter snampmirror name (with option --name). +Filter the snapmirror name (can be a regexp). =item B<--filter-status> @@ -197,17 +247,17 @@ Example: --filter-counters='^status$' =item B<--unknown-status> Set warning threshold for status (Default: ''). -Can used special variables like: %{status}, %{display} +Can used special variables like: %{state}, %{display} =item B<--warning-status> -Set warning threshold for status (Default: '%{status} =~ /quiesced/i'). -Can used special variables like: %{status}, %{display} +Set warning threshold for status (Default: '%{state} =~ /quiesced/i'). +Can used special variables like: %{state}, %{display} =item B<--critical-status> -Set critical threshold for status (Default: '%{status} =~ /unknown|brokenOff|uninitialized/i'). -Can used special variables like: %{status}, %{display} +Set critical threshold for status (Default: '%{state} =~ /unknown|brokenOff|uninitialized/i'). +Can used special variables like: %{state}, %{display} =item B<--warning-lag>