From f6bc581f99d722fbc6e297a48a9ffb2f39f753ec Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 15 Jan 2019 13:28:23 +0100 Subject: [PATCH] WIP: factoring with status catalog function (network parts) --- .../cloudgen/snmp/mode/boxservice.pm | 42 ++--------------- .../cloudgen/snmp/mode/serverservice.pm | 42 ++--------------- .../barracuda/cloudgen/snmp/mode/vpnstatus.pm | 42 ++--------------- .../beeware/snmp/mode/reverseproxyusage.pm | 42 ++--------------- network/colubris/snmp/mode/apusage.pm | 42 ++--------------- network/freebox/restapi/mode/system.pm | 45 ++----------------- .../common/junos/mode/ldpsessionstatus.pm | 42 ++--------------- .../juniper/common/junos/mode/lspstatus.pm | 42 ++--------------- .../common/junos/mode/rsvpsessionstatus.pm | 42 ++--------------- .../common/screenos/snmp/mode/vpnstatus.pm | 42 ++--------------- network/juniper/trapeze/snmp/mode/apstatus.pm | 42 ++--------------- network/nokia/timos/snmp/mode/bgpusage.pm | 42 ++--------------- network/nokia/timos/snmp/mode/isisusage.pm | 42 ++--------------- network/nokia/timos/snmp/mode/l2tpusage.pm | 42 ++--------------- network/nokia/timos/snmp/mode/ldpusage.pm | 42 ++--------------- network/nokia/timos/snmp/mode/sapusage.pm | 42 ++--------------- .../infiniband/snmp/mode/infinibandusage.pm | 43 +++++++----------- .../radware/alteon/snmp/mode/vserverstatus.pm | 42 ++--------------- network/sonus/sbc/snmp/mode/channels.pm | 42 ++--------------- network/sonus/sbc/snmp/mode/dspstats.pm | 44 ++---------------- network/zyxel/snmp/mode/vpnstatus.pm | 42 ++--------------- 21 files changed, 77 insertions(+), 811 deletions(-) diff --git a/network/barracuda/cloudgen/snmp/mode/boxservice.pm b/network/barracuda/cloudgen/snmp/mode/boxservice.pm index 3a174a0d5..26e27d29b 100644 --- a/network/barracuda/cloudgen/snmp/mode/boxservice.pm +++ b/network/barracuda/cloudgen/snmp/mode/boxservice.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -80,7 +55,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, } }, ]; @@ -112,18 +87,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_status = ( diff --git a/network/barracuda/cloudgen/snmp/mode/serverservice.pm b/network/barracuda/cloudgen/snmp/mode/serverservice.pm index 7d83b805a..551551b09 100644 --- a/network/barracuda/cloudgen/snmp/mode/serverservice.pm +++ b/network/barracuda/cloudgen/snmp/mode/serverservice.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -80,7 +55,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, } }, ]; @@ -112,18 +87,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_status = ( diff --git a/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm b/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm index d6e9088a0..9b0730b8f 100644 --- a/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm +++ b/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -80,7 +55,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, } }, ]; @@ -112,18 +87,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_status = ( diff --git a/network/beeware/snmp/mode/reverseproxyusage.pm b/network/beeware/snmp/mode/reverseproxyusage.pm index 11eb6d483..5a74241e7 100644 --- a/network/beeware/snmp/mode/reverseproxyusage.pm +++ b/network/beeware/snmp/mode/reverseproxyusage.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -79,7 +54,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 => 'cpu', set => { @@ -133,18 +108,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub prefix_rp_output { diff --git a/network/colubris/snmp/mode/apusage.pm b/network/colubris/snmp/mode/apusage.pm index 1a25b3346..11575832d 100644 --- a/network/colubris/snmp/mode/apusage.pm +++ b/network/colubris/snmp/mode/apusage.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_ap_status}) && $instance_mode->{option_results}->{critical_ap_status} ne '' && - eval "$instance_mode->{option_results}->{critical_ap_status}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_ap_status}) && $instance_mode->{option_results}->{warning_ap_status} ne '' && - eval "$instance_mode->{option_results}->{warning_ap_status}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -100,7 +75,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 => 'ap-users', set => { @@ -136,22 +111,11 @@ sub new { return $self; } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_ap_status', 'critical_ap_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(); - $instance_mode = $self; + $self->change_macros(macros => ['warning_ap_status', 'critical_ap_status']); } my %map_device_state = ( diff --git a/network/freebox/restapi/mode/system.pm b/network/freebox/restapi/mode/system.pm index e0ea6fa05..7f0b55407 100644 --- a/network/freebox/restapi/mode/system.pm +++ b/network/freebox/restapi/mode/system.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub set_counters { my ($self, %options) = @_; @@ -76,7 +76,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_disk_status_calc'), closure_custom_output => $self->can('custom_disk_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, @@ -88,38 +88,12 @@ sub set_counters { closure_custom_calc => $self->can('custom_wifi_status_calc'), closure_custom_output => $self->can('custom_wifi_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; } -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'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} - sub custom_disk_status_output { my ($self, %options) = @_; my $msg = 'Disk status : ' . $self->{result_values}->{status}; @@ -170,18 +144,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_wifi_status', 'critical_wifi_status', 'warning_disk_status', 'critical_disk_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } + $self->change_macros(macros => ['warning_wifi_status', 'critical_wifi_status', 'warning_disk_status', 'critical_disk_status']); } sub manage_selection { diff --git a/network/juniper/common/junos/mode/ldpsessionstatus.pm b/network/juniper/common/junos/mode/ldpsessionstatus.pm index f148a6286..5fa4ae42b 100644 --- a/network/juniper/common/junos/mode/ldpsessionstatus.pm +++ b/network/juniper/common/junos/mode/ldpsessionstatus.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -85,7 +60,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 => 'last-change', set => { @@ -118,22 +93,11 @@ sub new { return $self; } -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 check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_state = ( diff --git a/network/juniper/common/junos/mode/lspstatus.pm b/network/juniper/common/junos/mode/lspstatus.pm index 973d8b895..cc36a66a7 100644 --- a/network/juniper/common/junos/mode/lspstatus.pm +++ b/network/juniper/common/junos/mode/lspstatus.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -85,7 +60,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 => 'transition-count', set => { @@ -128,22 +103,11 @@ sub new { return $self; } -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 check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_state = ( diff --git a/network/juniper/common/junos/mode/rsvpsessionstatus.pm b/network/juniper/common/junos/mode/rsvpsessionstatus.pm index 0f4d35bd9..d1af52154 100644 --- a/network/juniper/common/junos/mode/rsvpsessionstatus.pm +++ b/network/juniper/common/junos/mode/rsvpsessionstatus.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -85,7 +60,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, } }, ]; @@ -109,22 +84,11 @@ sub new { return $self; } -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 check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_state = ( diff --git a/network/juniper/common/screenos/snmp/mode/vpnstatus.pm b/network/juniper/common/screenos/snmp/mode/vpnstatus.pm index e4f8b62e6..29f520e1f 100644 --- a/network/juniper/common/screenos/snmp/mode/vpnstatus.pm +++ b/network/juniper/common/screenos/snmp/mode/vpnstatus.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -94,7 +69,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 => 'update-time', set => { @@ -129,18 +104,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_state = (0 => 'inactive', 1 => 'active'); diff --git a/network/juniper/trapeze/snmp/mode/apstatus.pm b/network/juniper/trapeze/snmp/mode/apstatus.pm index c2684dadd..695d1af4d 100644 --- a/network/juniper/trapeze/snmp/mode/apstatus.pm +++ b/network/juniper/trapeze/snmp/mode/apstatus.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -sub custom_threshold_output { - my ($self, %options) = @_; - my $status = 'ok'; - my $message; - - eval { - 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}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -95,7 +70,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_threshold_output'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -121,8 +96,7 @@ 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']); } sub skip_global { @@ -137,16 +111,6 @@ sub prefix_ap_output { return "AP '" . $options{instance_value}->{display} . "' "; } -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; - } - } -} - my %map_ap_status = ( 1 => 'cleared', 2 => 'init', diff --git a/network/nokia/timos/snmp/mode/bgpusage.pm b/network/nokia/timos/snmp/mode/bgpusage.pm index da2409693..6809ac5ed 100644 --- a/network/nokia/timos/snmp/mode/bgpusage.pm +++ b/network/nokia/timos/snmp/mode/bgpusage.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -79,7 +54,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 => 'active-prefixes', set => { @@ -138,18 +113,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_status = (1 => 'unknown', 2 => 'inService', 3 => 'outOfService', diff --git a/network/nokia/timos/snmp/mode/isisusage.pm b/network/nokia/timos/snmp/mode/isisusage.pm index 920266a97..8c05881ec 100644 --- a/network/nokia/timos/snmp/mode/isisusage.pm +++ b/network/nokia/timos/snmp/mode/isisusage.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -102,7 +77,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, } }, ]; @@ -161,18 +136,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_admin_status = (1 => 'noop', 2 => 'inService', 3 => 'outOfService'); diff --git a/network/nokia/timos/snmp/mode/l2tpusage.pm b/network/nokia/timos/snmp/mode/l2tpusage.pm index a028654d5..752b5e4c8 100644 --- a/network/nokia/timos/snmp/mode/l2tpusage.pm +++ b/network/nokia/timos/snmp/mode/l2tpusage.pm @@ -26,32 +26,7 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); use Socket; - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -108,7 +83,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, } }, ]; @@ -219,18 +194,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_status = (1 => 'unknown', 2 => 'idle', 3 => 'waitReply', 4 => 'waitConn', diff --git a/network/nokia/timos/snmp/mode/ldpusage.pm b/network/nokia/timos/snmp/mode/ldpusage.pm index 88bc7f2bd..40dd46244 100644 --- a/network/nokia/timos/snmp/mode/ldpusage.pm +++ b/network/nokia/timos/snmp/mode/ldpusage.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -81,7 +56,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 => 'ipv4-active-sessions', set => { @@ -149,18 +124,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_oper_state = (1 => 'unknown', 2 => 'inService', 3 => 'outOfService', 4 => 'transition'); diff --git a/network/nokia/timos/snmp/mode/sapusage.pm b/network/nokia/timos/snmp/mode/sapusage.pm index 1b9e61ce4..2048eecdf 100644 --- a/network/nokia/timos/snmp/mode/sapusage.pm +++ b/network/nokia/timos/snmp/mode/sapusage.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -81,7 +56,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 => { @@ -153,18 +128,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_admin_status = (1 => 'up', 2 => 'down'); diff --git a/network/oracle/infiniband/snmp/mode/infinibandusage.pm b/network/oracle/infiniband/snmp/mode/infinibandusage.pm index 7f1ad2258..7fe8d590a 100644 --- a/network/oracle/infiniband/snmp/mode/infinibandusage.pm +++ b/network/oracle/infiniband/snmp/mode/infinibandusage.pm @@ -26,8 +26,6 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); -my $instance_mode; - sub set_counters { my ($self, %options) = @_; @@ -105,17 +103,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}->{status} ne 'down') { - $instance_mode->{last_status} = 1; + $self->{instance_mode}->{last_status} = 1; } }; if (defined($message)) { @@ -149,10 +147,10 @@ sub custom_ib_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}); } @@ -168,9 +166,9 @@ sub custom_ib_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; @@ -195,7 +193,7 @@ sub custom_ib_output { sub custom_ib_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'}; @@ -204,9 +202,9 @@ sub custom_ib_calc { if ($options{new_datas}->{$self->{instance} . '_speed_' . $self->{result_values}->{label}} > 0) { $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $self->{result_values}->{label}} * 1000 * 1000; $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / $self->{result_values}->{speed}; - } elsif (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; + } elsif (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; } @@ -237,18 +235,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_ib_status', 'critical_ib_status', 'warning_ibgw_status', 'critical_ibgw_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } + $self->change_macros(macros => ['warning_ib_status', 'critical_ib_status', 'warning_ibgw_status', 'critical_ibgw_status']); } sub prefix_ib_output { diff --git a/network/radware/alteon/snmp/mode/vserverstatus.pm b/network/radware/alteon/snmp/mode/vserverstatus.pm index 58ee4ff42..18d2cb2ef 100644 --- a/network/radware/alteon/snmp/mode/vserverstatus.pm +++ b/network/radware/alteon/snmp/mode/vserverstatus.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -80,7 +55,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', set => { @@ -140,18 +115,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); -} - -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; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_state = ( diff --git a/network/sonus/sbc/snmp/mode/channels.pm b/network/sonus/sbc/snmp/mode/channels.pm index f41cd0c9b..3aa4ccfb8 100644 --- a/network/sonus/sbc/snmp/mode/channels.pm +++ b/network/sonus/sbc/snmp/mode/channels.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -sub custom_threshold_output { - my ($self, %options) = @_; - my $status = 'ok'; - my $message; - - eval { - 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}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -251,7 +226,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_threshold_output'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, { label => 'seconds', set => { @@ -285,8 +260,7 @@ 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']); } sub prefix_channels_output { @@ -295,16 +269,6 @@ sub prefix_channels_output { return "Channels '" . $options{instance_value}->{display} . "' "; } -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; - } - } -} - my %map_admin_status = ( 0 => 'down', 1 => 'up', diff --git a/network/sonus/sbc/snmp/mode/dspstats.pm b/network/sonus/sbc/snmp/mode/dspstats.pm index 492fc0b79..73a2ae7ad 100644 --- a/network/sonus/sbc/snmp/mode/dspstats.pm +++ b/network/sonus/sbc/snmp/mode/dspstats.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -sub custom_threshold_output { - my ($self, %options) = @_; - my $status = 'ok'; - my $message; - - eval { - 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}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_state_output { my ($self, %options) = @_; @@ -73,12 +48,12 @@ sub set_counters { { name => 'dsp', type => 1, cb_prefix_output => 'prefix_dsp_output', message_multiple => 'All DSP stats and states are OK' }, ]; $self->{maps_counters}->{dsp} = [ - { label => 'state', threshold => 0, set => { + { label => 'status', threshold => 0, set => { key_values => [ { name => 'state' }, { name => 'display' } ], closure_custom_calc => \&custom_state_calc, closure_custom_output => \&custom_state_output, closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&custom_threshold_output, + closure_custom_threshold_check => \&catalog_status_threshold, } }, { label => 'cpu', set => { @@ -122,22 +97,11 @@ sub new { return $self; } -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 check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(); - $instance_mode = $self; + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_status = ( diff --git a/network/zyxel/snmp/mode/vpnstatus.pm b/network/zyxel/snmp/mode/vpnstatus.pm index eb5c4dbb4..f5e387b74 100644 --- a/network/zyxel/snmp/mode/vpnstatus.pm +++ b/network/zyxel/snmp/mode/vpnstatus.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); - -my $instance_mode; - -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]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$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}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -81,7 +56,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', set => { @@ -128,22 +103,11 @@ sub new { return $self; } -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 check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(); - $instance_mode = $self; + $self->change_macros(macros => ['warning_status', 'critical_status']); } my %map_active_status = (0 => 'inactive', 1 => 'active');