--- /usr/lib/centreon/plugins/centreon_cisco_standard_snmp.pl 2017-12-08 13:15:39.000000000 +0100 +++ /home/administrateur/centreon_cisco_standard_snmp.pl 2018-03-13 17:29:34.696613090 +0100 @@ -6688,6 +6688,7 @@ $fatpacked{"centreon/plugins/snmp.pm"} = "contextengineid:s" => { name => 'snmp_context_engine_id' }, "securityengineid:s" => { name => 'snmp_security_engine_id' }, "snmp-errors-exit:s" => { name => 'snmp_errors_exit', default => 'unknown' }, + "stp-overrite-status:s" => { name => 'stp_overwrite_status' }, }); $options{options}->add_help(package => __PACKAGE__, sections => 'SNMP OPTIONS'); @@ -10834,6 +10835,8 @@ $fatpacked{"snmp_standard/mode/spanningt use strict; use warnings; + + my $instance_mode; my %states = ( 1 => ['disabled', 'OK'], @@ -10850,6 +10853,10 @@ $fatpacked{"snmp_standard/mode/spanningt my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; + $options{options}->add_options(arguments => + { + "stp-overrite-status:s" => { name => 'stp_overwrite_status' }, + }); $self->{version} = '1.0'; $options{options}->add_options(arguments => @@ -10859,9 +10866,20 @@ $fatpacked{"snmp_standard/mode/spanningt return $self; } + sub change_macros { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{stp_overwrite_status})) { + $self->{option_results}->{stp_overwrite_status} = $self->{option_results}->{stp_overwrite_status}; + } + } + sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + $instance_mode = $self; + $self->change_macros(); } sub run { @@ -10891,6 +10909,12 @@ $fatpacked{"snmp_standard/mode/spanningt } + my @stp_overwrite_status = {}; + if (defined($self->{option_results}->{stp_overwrite_status})) { + @stp_overwrite_status = split /:/, $self->{option_results}->{stp_overwrite_status}; + $self->{output}->output_add(long_msg => "Found " . ((scalar $#stp_overwrite_status)+1) . " custom STP topology"); + } + $self->{snmp}->load(oids => [$oid_dot1dBasePortIfIndex], instances => [@instances]); my $result = $self->{snmp}->get_leef(nothing_quit => 1); @@ -10912,10 +10936,27 @@ $fatpacked{"snmp_standard/mode/spanningt $self->{output}->output_add(long_msg => sprintf("Spanning Tree interface '%s' state is %s", $descr, ${$states{$stp_state}}[0])); - if (${$states{$stp_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states{$stp_state}}[1], - short_msg => sprintf("Spanning Tree interface '%s' state is %s", $descr, - ${$states{$stp_state}}[0])); + + my $custom_status = 'forwarding'; + + for (my $e=0; $e <= (scalar $#stp_overwrite_status); $e++ ) { + my @stp_overwrite_status_ports = split /\@/, $stp_overwrite_status[$e]; + if ( $stp_overwrite_status_ports[0] eq $descr ) { + $custom_status = $stp_overwrite_status_ports[1]; + } + } + + if (${$states{$stp_state}}[0] ne ${custom_status}) { + if($custom_status ne 'forwarding') { + $self->{output}->output_add(severity => ${$states{6}}[1], + short_msg => sprintf("Spanning Tree interface '%s' state is %s should be %s", $descr, + ${$states{$stp_state}}[0], $custom_status)); + + } else { + $self->{output}->output_add(severity => ${$states{$stp_state}}[1], + short_msg => sprintf("Spanning Tree interface '%s' state is %s", $descr, + ${$states{$stp_state}}[0])); + } } }