From 047eb44be9caa3354dd1c129d5c1f3a35d277469 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 15 Jan 2019 12:15:08 +0100 Subject: [PATCH] WIP: factoring with status catalog function (network parts) --- network/adva/fsp3000/snmp/mode/interfaces.pm | 13 ++--- network/alcatel/isam/snmp/mode/hubsapusage.pm | 58 ++++++++----------- .../alcatel/pss/1830/snmp/mode/sapqosstats.pm | 49 +--------------- network/atrica/snmp/mode/connections.pm | 15 ++--- .../mrv/optiswitch/snmp/mode/interfaces.pm | 3 - snmp_standard/mode/interfaces.pm | 51 +++++++--------- 6 files changed, 58 insertions(+), 131 deletions(-) diff --git a/network/adva/fsp3000/snmp/mode/interfaces.pm b/network/adva/fsp3000/snmp/mode/interfaces.pm index c349262a7..5130ce721 100644 --- a/network/adva/fsp3000/snmp/mode/interfaces.pm +++ b/network/adva/fsp3000/snmp/mode/interfaces.pm @@ -25,8 +25,6 @@ use base qw(snmp_standard::mode::interfaces); use strict; use warnings; -my $instance_mode; - sub set_oids_traffic { my ($self, %options) = @_; @@ -105,10 +103,10 @@ sub custom_traffic_perfdata { } my ($warning, $critical); - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); } @@ -124,9 +122,9 @@ sub custom_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); } return $exit; @@ -148,7 +146,7 @@ sub custom_traffic_output { sub custom_traffic_calc { my ($self, %options) = @_; - return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); # we choose the performance value (1day is updated every 15 minutes. 15min is updated all the time but reset every 15min my $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_15min'; @@ -181,7 +179,6 @@ sub new { } ); - $instance_mode = $self; return $self; } diff --git a/network/alcatel/isam/snmp/mode/hubsapusage.pm b/network/alcatel/isam/snmp/mode/hubsapusage.pm index ba020a52c..ce02eeec3 100644 --- a/network/alcatel/isam/snmp/mode/hubsapusage.pm +++ b/network/alcatel/isam/snmp/mode/hubsapusage.pm @@ -26,8 +26,7 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); use centreon::plugins::statefile; - -my $instance_mode; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub set_counters { my ($self, %options) = @_; @@ -92,10 +91,10 @@ sub custom_total_traffic_perfdata { my ($self, %options) = @_; my ($warning, $critical); - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); } @@ -111,9 +110,9 @@ sub custom_total_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{total_traffic}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); } return $exit; @@ -156,9 +155,9 @@ sub custom_total_traffic_calc { $self->{result_values}->{label} = $options{extra_options}->{label_ref}; $self->{result_values}->{total_traffic} = $total_traffic / $options{delta_time}; - if (defined($instance_mode->{option_results}->{'speed_total_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_total_' . $self->{result_values}->{label}} =~ /[0-9]/) { - $self->{result_values}->{traffic_prct} = $self->{result_values}->{total_traffic} * 100 / ($instance_mode->{option_results}->{'speed_total_' . $self->{result_values}->{label}} * 1000 * 1000); - $self->{result_values}->{speed} = $instance_mode->{option_results}->{'speed_total_' . $self->{result_values}->{label}} * 1000 * 1000; + if (defined($self->{instance_mode}->{option_results}->{'speed_total_' . $self->{result_values}->{label}}) && $self->{instance_mode}->{option_results}->{'speed_total_' . $self->{result_values}->{label}} =~ /[0-9]/) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{total_traffic} * 100 / ($self->{instance_mode}->{option_results}->{'speed_total_' . $self->{result_values}->{label}} * 1000 * 1000); + $self->{result_values}->{speed} = $self->{instance_mode}->{option_results}->{'speed_total_' . $self->{result_values}->{label}} * 1000 * 1000; } return 0; } @@ -174,17 +173,17 @@ sub custom_status_threshold { my $label = $self->{label}; $label =~ s/-/_/g; - if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' && - eval "$instance_mode->{option_results}->{'critical_' . $label}") { + if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' && + eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") { $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' && - eval "$instance_mode->{option_results}->{'warning_' . $label}") { + } elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' && + eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") { $status = 'warning'; } - $instance_mode->{last_status} = 0; + $self->{instance_mode}->{last_status} = 0; if ($self->{result_values}->{admin} eq 'up') { - $instance_mode->{last_status} = 1; + $self->{instance_mode}->{last_status} = 1; } }; if (defined($message)) { @@ -219,10 +218,10 @@ sub custom_sap_perfdata { } my ($warning, $critical); - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); } @@ -238,9 +237,9 @@ sub custom_sap_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); } return $exit; @@ -265,13 +264,13 @@ sub custom_sap_output { sub custom_sap_calc { my ($self, %options) = @_; - return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); $self->{result_values}->{label} = $options{extra_options}->{label_ref}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{traffic} = ($options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}} - $options{old_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}}) / $options{delta_time}; - if (defined($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { - $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000); - $self->{result_values}->{speed} = $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000; + if (defined($self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000); + $self->{result_values}->{speed} = $self->{instance_mode}->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000; } return 0; } @@ -304,21 +303,10 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); $self->{statefile_cache}->check_options(%options); } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_status', 'critical_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub prefix_sap_output { my ($self, %options) = @_; diff --git a/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm b/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm index d78819f74..0a05b3d51 100644 --- a/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm +++ b/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm @@ -26,8 +26,7 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); use centreon::plugins::statefile; - -my $instance_mode; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub set_counters { my ($self, %options) = @_; @@ -42,7 +41,7 @@ sub set_counters { 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 => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, { label => 'traffic-in-below-cir', set => { @@ -88,37 +87,6 @@ sub set_counters { ]; } -sub custom_status_threshold { - my ($self, %options) = @_; - my $status = 'ok'; - my $message; - - eval { - local $SIG{__WARN__} = sub { $message = $_[0]; }; - local $SIG{__DIE__} = sub { $message = $_[0]; }; - - my $label = $self->{label}; - $label =~ s/-/_/g; - if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' && - eval "$instance_mode->{option_results}->{'critical_' . $label}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' && - eval "$instance_mode->{option_results}->{'warning_' . $label}") { - $status = 'warning'; - } - - $instance_mode->{last_status} = 0; - if ($self->{result_values}->{admin} eq 'up') { - $instance_mode->{last_status} = 1; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} - sub custom_status_output { my ($self, %options) = @_; my $msg = 'Status : ' . $self->{result_values}->{status} . ' (admin: ' . $self->{result_values}->{admin} . ')'; @@ -158,21 +126,10 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); $self->{statefile_cache}->check_options(%options); } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_status', 'critical_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub prefix_sap_output { my ($self, %options) = @_; diff --git a/network/atrica/snmp/mode/connections.pm b/network/atrica/snmp/mode/connections.pm index 82583a416..59fcc3233 100644 --- a/network/atrica/snmp/mode/connections.pm +++ b/network/atrica/snmp/mode/connections.pm @@ -25,8 +25,6 @@ use base qw(snmp_standard::mode::interfaces); use strict; use warnings; -my $instance_mode; - sub set_oids_label { my ($self, %options) = @_; @@ -221,10 +219,10 @@ sub custom_traffic_perfdata { } my ($warning, $critical); - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); } @@ -240,9 +238,9 @@ sub custom_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); } return $exit; @@ -264,10 +262,10 @@ sub custom_traffic_output { sub custom_traffic_calc { my ($self, %options) = @_; - return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); - if ($diff_traffic == 0 && !defined($instance_mode->{option_results}->{no_skipped_counters})) { + if ($diff_traffic == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { $self->{error_msg} = "skipped"; return -2; } @@ -290,7 +288,6 @@ sub new { no_set_traffic => 1, no_set_errors => 1, no_cast => 1); bless $self, $class; - $instance_mode = $self; return $self; } diff --git a/network/mrv/optiswitch/snmp/mode/interfaces.pm b/network/mrv/optiswitch/snmp/mode/interfaces.pm index 45e46aa0f..e9d230847 100644 --- a/network/mrv/optiswitch/snmp/mode/interfaces.pm +++ b/network/mrv/optiswitch/snmp/mode/interfaces.pm @@ -25,8 +25,6 @@ use base qw(snmp_standard::mode::interfaces); use strict; use warnings; -my $instance_mode; - sub custom_status_output { my ($self, %options) = @_; my $msg = 'Status : ' . $self->{result_values}->{linkstatus} . ' (oper: ' . $self->{result_values}->{opstatus} . ', ' . 'admin: ' . $self->{result_values}->{admstatus} . ')'; @@ -401,7 +399,6 @@ sub new { "global-link-down-rule:s" => { name => 'global_link_down_rule', default => $self->default_global_link_down_rule() }, }); - $instance_mode = $self; return $self; } diff --git a/snmp_standard/mode/interfaces.pm b/snmp_standard/mode/interfaces.pm index b0bbc7042..a18972233 100644 --- a/snmp_standard/mode/interfaces.pm +++ b/snmp_standard/mode/interfaces.pm @@ -28,8 +28,6 @@ use centreon::plugins::values; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); -my $instance_mode; - ######################### # Calc functions ######################### @@ -42,17 +40,17 @@ sub custom_threshold_output { local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; }; - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$instance_mode->{option_results}->{critical_status}") { + if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' && + eval "$self->{instance_mode}->{option_results}->{critical_status}") { $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { + } elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' && + eval "$self->{instance_mode}->{option_results}->{warning_status}") { $status = 'warning'; } - $instance_mode->{last_status} = 0; - if (eval "$instance_mode->{check_status}") { - $instance_mode->{last_status} = 1; + $self->{instance_mode}->{last_status} = 0; + if (eval "$self->{instance_mode}->{check_status}") { + $self->{instance_mode}->{last_status} = 1; } }; if (defined($message)) { @@ -81,7 +79,7 @@ sub custom_status_calc { sub custom_cast_calc { my ($self, %options) = @_; - return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); if ($options{new_datas}->{$self->{instance} . '_mode_cast'} ne $options{old_datas}->{$self->{instance} . '_mode_cast'}) { $self->{error_msg} = "buffer creation"; return -2; @@ -92,7 +90,7 @@ sub custom_cast_calc { + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); - if ($total == 0 && !defined($instance_mode->{option_results}->{no_skipped_counters})) { + if ($total == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { $self->{error_msg} = "skipped"; return -2; } @@ -111,21 +109,21 @@ sub custom_traffic_perfdata { if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { $extra_label .= '_' . $self->{result_values}->{display}; } - if (defined($instance_mode->{option_results}->{nagvis_perfdata})) { + if (defined($self->{instance_mode}->{option_results}->{nagvis_perfdata})) { $self->{result_values}->{traffic_per_seconds} /= 8; $self->{result_values}->{speed} /= 8 if (defined($self->{result_values}->{speed})); } my ($warning, $critical); - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); } - if (defined($instance_mode->{option_results}->{nagvis_perfdata})) { + if (defined($self->{instance_mode}->{option_results}->{nagvis_perfdata})) { $self->{output}->perfdata_add(label => $self->{result_values}->{label} . $extra_label, value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), warning => $warning, @@ -144,9 +142,9 @@ sub custom_traffic_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); } return $exit; @@ -165,14 +163,14 @@ sub custom_traffic_output { sub custom_traffic_calc { my ($self, %options) = @_; - return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); if ($options{new_datas}->{$self->{instance} . '_mode_traffic'} ne $options{old_datas}->{$self->{instance} . '_mode_traffic'}) { $self->{error_msg} = "buffer creation"; return -2; } my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); - if ($diff_traffic == 0 && !defined($instance_mode->{option_results}->{no_skipped_counters})) { + if ($diff_traffic == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { $self->{error_msg} = "skipped"; return -2; } @@ -198,7 +196,7 @@ sub custom_errors_perfdata { if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { $extra_label .= '_' . $self->{result_values}->{display}; } - if ($instance_mode->{option_results}->{units_errors} eq '%') { + if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { $self->{output}->perfdata_add(label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1} . $extra_label, unit => '%', value => sprintf("%.2f", $self->{result_values}->{prct}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), @@ -217,7 +215,7 @@ sub custom_errors_threshold { my ($self, %options) = @_; my $exit = 'ok'; - if ($instance_mode->{option_results}->{units_errors} eq '%') { + if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); } else { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); @@ -237,7 +235,7 @@ sub custom_errors_output { sub custom_errors_calc { my ($self, %options) = @_; - return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); if ($options{new_datas}->{$self->{instance} . '_mode_cast'} ne $options{old_datas}->{$self->{instance} . '_mode_cast'}) { $self->{error_msg} = "buffer creation"; return -2; @@ -247,7 +245,7 @@ sub custom_errors_calc { $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}}); my $total = ($options{new_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'} - $options{old_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'}); - if ($total == 0 && !defined($instance_mode->{option_results}->{no_skipped_counters})) { + if ($total == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { $self->{error_msg} = "skipped"; return -2; } @@ -535,12 +533,6 @@ sub set_key_values_out_traffic { return [ { name => 'out', diff => 1 }, { name => 'speed_out'}, { name => 'display' }, { name => 'mode_traffic' } ]; } -sub set_instance { - my ($self, %options) = @_; - - $instance_mode = $self; -} - sub set_oids_label { my ($self, %options) = @_; @@ -793,7 +785,6 @@ sub check_options { $self->set_oids_label(); $self->check_oids_label(); - $self->set_instance(); $self->{statefile_cache}->check_options(%options); $self->{statefile_value}->check_options(%options);