From b4f2585702ae02fa50cc490d643ab72d14c4c7a5 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 13 Jun 2019 17:39:06 +0200 Subject: [PATCH] Fix #1547 --- .../common/cisco/standard/snmp/mode/hsrp.pm | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/centreon/common/cisco/standard/snmp/mode/hsrp.pm b/centreon/common/cisco/standard/snmp/mode/hsrp.pm index 0928f6b7e..717be51ba 100644 --- a/centreon/common/cisco/standard/snmp/mode/hsrp.pm +++ b/centreon/common/cisco/standard/snmp/mode/hsrp.pm @@ -48,10 +48,11 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "role:s" => { name => 'role', default => 'primary' }, - }); + $options{options}->add_options(arguments => { + 'role:s' => { name => 'role', default => 'primary' }, + 'filter-vrid:s' => { name => 'filter_vrid' }, + }); + return $self; } @@ -73,18 +74,26 @@ sub run { my $oid_cHsrpGrpStandbyState = ".1.3.6.1.4.1.9.9.106.1.2.1.1.15"; # HSRP Oper Status my $oid_cHsrpGrpEntryRowStatus = ".1.3.6.1.4.1.9.9.106.1.2.1.1.17"; # HSRP Admin Status - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cHsrpGrpStandbyState }, - { oid => $oid_cHsrpGrpEntryRowStatus }, - ], - nothing_quit => 1); + my $results = $self->{snmp}->get_multiple_table(oids => + [ + { oid => $oid_cHsrpGrpStandbyState }, + { oid => $oid_cHsrpGrpEntryRowStatus }, + ], + nothing_quit => 1 + ); $self->{output}->output_add(severity => 'OK', short_msg => sprintf("Router is in its expected state : '%s'", $self->{option_results}->{role})); foreach my $oid (keys %{$results->{$oid_cHsrpGrpStandbyState}}) { $oid =~ /(\d+\.\d+)$/; my $vrid = $1; - + + if (defined($self->{option_results}->{filter_vrid}) && $self->{option_results}->{filter_vrid} ne '' && + $vrid !~ /$self->{option_results}->{filter_vrid}/) { + $self->{output}->output_add(long_msg => "skipping vrid '" . $vrid . "': no matching filter.", debug => 1); + next; + } + my $operState = $results->{$oid_cHsrpGrpEntryRowStatus}->{$oid_cHsrpGrpEntryRowStatus . "." . $vrid}; my $adminState = $results->{$oid_cHsrpGrpStandbyState}->{$oid}; @@ -121,6 +130,10 @@ Check Cisco HSRP (CISCO-HSRP-MIB). Trigger a critical if not in the expected sta =over 8 +=item B<--filter-vrid> + +Filter VRID (can be a regexp). + =item B<--role> If role is 'primary', an error if HSRPs are 'standby' states.