From fadfdf4f93a9712942fd4c0c9c9d640f0dc39f0a Mon Sep 17 00:00:00 2001 From: itoussies <65223458+itoussies@users.noreply.github.com> Date: Tue, 19 Jan 2021 11:37:30 +0100 Subject: [PATCH] enh(plugin)apps-protocol-ospf-snmp metricsv2 (#2525) --- apps/protocols/ospf/snmp/mode/neighbor.pm | 47 +++++++++-------------- apps/protocols/ospf/snmp/plugin.pm | 6 +-- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/apps/protocols/ospf/snmp/mode/neighbor.pm b/apps/protocols/ospf/snmp/mode/neighbor.pm index b93d12ced..bae3f1a45 100644 --- a/apps/protocols/ospf/snmp/mode/neighbor.pm +++ b/apps/protocols/ospf/snmp/mode/neighbor.pm @@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub custom_status_output { my ($self, %options) = @_; @@ -58,6 +58,12 @@ sub custom_change_calc { return 0; } +sub prefix_nb_output { + my ($self, %options) = @_; + + return "Neighbor '" . $options{instance_value}->{NbrIpAddr} . "/" . $options{instance_value}->{NbrRtrId} . "' "; +} + sub set_counters { my ($self, %options) = @_; @@ -67,13 +73,12 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'total', set => { + { label => 'total', nlabel => 'neighbors.total.count',set => { key_values => [ { name => 'total' } ], output_template => 'Total neighbors : %s', perfdatas => [ - { label => 'total', value => 'total', template => '%s', - min => 0 }, - ], + { label => 'total', template => '%s', min => 0 } + ] } }, { label => 'total-change', threshold => 0, set => { @@ -81,17 +86,21 @@ sub set_counters { closure_custom_calc => $self->can('custom_change_calc'), closure_custom_output => $self->can('custom_change_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, ]; $self->{maps_counters}->{nb} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', + type => 2, + critical_default => '%{NbrState} =~ /down/i', + set => { key_values => [ { name => 'NbrIpAddr' }, { name => 'NbrRtrId' }, { name => 'NbrState' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold_ng, } }, ]; @@ -102,30 +111,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{NbrState} =~ /down/i' }, - "warning-total-change:s" => { name => 'warning_total_change', default => '' }, - "critical-total-change:s" => { name => 'critical_total_change', default => '' }, - }); + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status', 'warning_total_change', 'critical_total_change']); -} - -sub prefix_nb_output { - my ($self, %options) = @_; - - return "Neighbor '" . $options{instance_value}->{NbrIpAddr} . "/" . $options{instance_value}->{NbrRtrId} . "' "; -} - my %map_state = ( 1 => 'down', 2 => 'attempt', diff --git a/apps/protocols/ospf/snmp/plugin.pm b/apps/protocols/ospf/snmp/plugin.pm index 8b79d00bf..ba3a215bf 100644 --- a/apps/protocols/ospf/snmp/plugin.pm +++ b/apps/protocols/ospf/snmp/plugin.pm @@ -30,9 +30,9 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'neighbor' => 'apps::protocols::ospf::snmp::mode::neighbor', - ); + $self->{modes} = { + 'neighbor' => 'apps::protocols::ospf::snmp::mode::neighbor' + }; return $self; }