From 77e6b0c8ed3979d659fde7ff1f232fdece595724 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 15 Jan 2019 10:49:51 +0100 Subject: [PATCH] WIP: factoring with status catalog function (cloud, database, os, snmp_standard parts) --- cloud/aws/cloudwatch/mode/getalarms.pm | 42 ++------------- cloud/aws/ec2/mode/asgstatus.pm | 43 ++------------- cloud/aws/ec2/mode/instancesstatus.pm | 44 ++-------------- cloud/aws/ec2/mode/status.pm | 23 ++------ cloud/aws/rds/mode/instancestatus.pm | 44 ++-------------- .../compute/virtualmachine/mode/vmsstate.pm | 44 ++-------------- .../resource/mode/deploymentsstatus.pm | 44 ++-------------- cloud/cloudfoundry/restapi/mode/appsstate.pm | 42 ++------------- .../restapi/mode/instancesstate.pm | 12 +---- cloud/docker/restapi/mode/containerusage.pm | 42 ++------------- cloud/docker/restapi/mode/nodestatus.pm | 42 ++------------- cloud/ibm/softlayer/mode/events.pm | 42 ++------------- cloud/ibm/softlayer/mode/opentickets.pm | 42 ++------------- .../management/mode/servicestatus.pm | 44 ++-------------- cloud/nutanix/snmp/mode/clusterusage.pm | 51 +++--------------- cloud/nutanix/snmp/mode/diskusage.pm | 52 +++---------------- .../direct/kubernetes/mode/containerstatus.pm | 42 ++------------- .../direct/kubernetes/mode/daemonsetstatus.pm | 42 ++------------- .../kubernetes/mode/deploymentstatus.pm | 42 ++------------- .../direct/kubernetes/mode/namespacestatus.pm | 42 ++------------- .../direct/kubernetes/mode/nodestatus.pm | 46 ++-------------- cloud/prometheus/restapi/mode/expression.pm | 48 +++-------------- cloud/prometheus/restapi/mode/targetstatus.pm | 42 ++------------- database/oracle/mode/datafilesstatus.pm | 44 ++-------------- database/oracle/mode/longqueries.pm | 42 ++------------- os/linux/local/mode/mountpoint.pm | 44 ++-------------- os/linux/local/mode/systemdscstatus.pm | 42 ++------------- os/windows/local/mode/pendingreboot.pm | 42 ++------------- snmp_standard/mode/spanningtree.pm | 40 ++------------ snmp_standard/mode/vrrp.pm | 44 ++-------------- 30 files changed, 109 insertions(+), 1146 deletions(-) diff --git a/cloud/aws/cloudwatch/mode/getalarms.pm b/cloud/aws/cloudwatch/mode/getalarms.pm index 9caed52fc..d00bed52c 100644 --- a/cloud/aws/cloudwatch/mode/getalarms.pm +++ b/cloud/aws/cloudwatch/mode/getalarms.pm @@ -26,32 +26,7 @@ use strict; use warnings; use centreon::plugins::misc; use centreon::plugins::statefile; - -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) = @_; @@ -89,7 +64,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, } }, ]; @@ -119,24 +94,13 @@ 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']); if (defined($self->{option_results}->{memory})) { $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 manage_selection { my ($self, %options) = @_; diff --git a/cloud/aws/ec2/mode/asgstatus.pm b/cloud/aws/ec2/mode/asgstatus.pm index efb3707ca..6a2b29e13 100644 --- a/cloud/aws/ec2/mode/asgstatus.pm +++ b/cloud/aws/ec2/mode/asgstatus.pm @@ -24,33 +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]; }; - - my $label = $self->{label}; - 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; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -126,7 +100,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, } }, ]; @@ -159,18 +133,7 @@ sub check_options { $self->{output}->option_exit(); } - $instance_mode = $self; - $self->change_macros(); -} - -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_instances', 'critical_instances')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } + $self->change_macros(macros => ['warning_instances', 'critical_instances']); } sub manage_selection { diff --git a/cloud/aws/ec2/mode/instancesstatus.pm b/cloud/aws/ec2/mode/instancesstatus.pm index 314c136a1..e25d4bb7d 100644 --- a/cloud/aws/ec2/mode/instancesstatus.pm +++ b/cloud/aws/ec2/mode/instancesstatus.pm @@ -24,34 +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]; }; - - 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; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -134,7 +107,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, } }, ]; @@ -166,8 +139,7 @@ sub check_options { $self->{output}->option_exit(); } - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub prefix_global_output { @@ -182,16 +154,6 @@ sub prefix_awsinstance_output { return "Instance '" . $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; - } - } -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/aws/ec2/mode/status.pm b/cloud/aws/ec2/mode/status.pm index 5853df6b3..519799225 100644 --- a/cloud/aws/ec2/mode/status.pm +++ b/cloud/aws/ec2/mode/status.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - my %map_type = ( "instance" => "InstanceId", "asg" => "AutoScalingGroupName", @@ -52,11 +50,11 @@ sub custom_status_threshold { 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'; } }; @@ -153,18 +151,7 @@ sub check_options { push @{$self->{aws_metrics}}, $metric; } - $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 manage_selection { diff --git a/cloud/aws/rds/mode/instancestatus.pm b/cloud/aws/rds/mode/instancestatus.pm index 67136866c..b11c63dc7 100644 --- a/cloud/aws/rds/mode/instancestatus.pm +++ b/cloud/aws/rds/mode/instancestatus.pm @@ -24,34 +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]; }; - - 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; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -134,7 +107,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, } }, ]; @@ -165,8 +138,7 @@ sub check_options { $self->{output}->option_exit(); } - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub prefix_global_output { @@ -181,16 +153,6 @@ sub prefix_awsinstance_output { return "Instance '" . $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; - } - } -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/azure/compute/virtualmachine/mode/vmsstate.pm b/cloud/azure/compute/virtualmachine/mode/vmsstate.pm index 937b40aa3..a9fb2c4aa 100644 --- a/cloud/azure/compute/virtualmachine/mode/vmsstate.pm +++ b/cloud/azure/compute/virtualmachine/mode/vmsstate.pm @@ -24,34 +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]; }; - - 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; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -113,7 +86,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, } }, ]; @@ -140,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']); } sub manage_selection { diff --git a/cloud/azure/management/resource/mode/deploymentsstatus.pm b/cloud/azure/management/resource/mode/deploymentsstatus.pm index 789974db6..c150068bb 100644 --- a/cloud/azure/management/resource/mode/deploymentsstatus.pm +++ b/cloud/azure/management/resource/mode/deploymentsstatus.pm @@ -24,34 +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]; }; - - 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; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_status_output { my ($self, %options) = @_; @@ -117,7 +90,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, } }, ]; @@ -148,18 +121,7 @@ sub check_options { $self->{output}->option_exit(); } - $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 manage_selection { diff --git a/cloud/cloudfoundry/restapi/mode/appsstate.pm b/cloud/cloudfoundry/restapi/mode/appsstate.pm index 8ac075813..19d897772 100644 --- a/cloud/cloudfoundry/restapi/mode/appsstate.pm +++ b/cloud/cloudfoundry/restapi/mode/appsstate.pm @@ -24,32 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; - -my $instance_mode; - -sub custom_state_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_state}) && $instance_mode->{option_results}->{critical_state} ne '' && - eval "$instance_mode->{option_results}->{critical_state}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_state}) && $instance_mode->{option_results}->{warning_state} ne '' && - eval "$instance_mode->{option_results}->{warning_state}") { - $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) = @_; @@ -108,7 +83,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_state_calc'), closure_custom_output => $self->can('custom_state_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_state_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -132,22 +107,11 @@ sub new { return $self; } -sub change_macros { - my ($self, %options) = @_; - - foreach ('warning_state', 'critical_state') { - 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_state', 'critical_state']); } sub manage_selection { diff --git a/cloud/cloudfoundry/restapi/mode/instancesstate.pm b/cloud/cloudfoundry/restapi/mode/instancesstate.pm index 50071a247..efad7fa68 100644 --- a/cloud/cloudfoundry/restapi/mode/instancesstate.pm +++ b/cloud/cloudfoundry/restapi/mode/instancesstate.pm @@ -194,16 +194,6 @@ sub new { return $self; } -sub change_macros { - my ($self, %options) = @_; - - foreach ('warning_app_state', 'critical_app_state', 'warning_instance_state', 'critical_instance_state') { - 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); @@ -214,7 +204,7 @@ sub check_options { } $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_app_state', 'critical_app_state', 'warning_instance_state', 'critical_instance_state']); } sub manage_selection { diff --git a/cloud/docker/restapi/mode/containerusage.pm b/cloud/docker/restapi/mode/containerusage.pm index 40f308b23..d3e931050 100644 --- a/cloud/docker/restapi/mode/containerusage.pm +++ b/cloud/docker/restapi/mode/containerusage.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_container_status}) && $instance_mode->{option_results}->{critical_container_status} ne '' && - eval "$instance_mode->{option_results}->{critical_container_status}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_container_status}) && $instance_mode->{option_results}->{warning_container_status} ne '' && - eval "$instance_mode->{option_results}->{warning_container_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) = @_; @@ -140,7 +115,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 => { @@ -232,8 +207,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_container_status', 'critical_container_status']); $self->{statefile_cache_containers}->check_options(%options); } @@ -249,16 +223,6 @@ sub prefix_containers_output { return "Container '" . $options{instance_value}->{display} . "' "; } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_container_status', 'critical_container_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/docker/restapi/mode/nodestatus.pm b/cloud/docker/restapi/mode/nodestatus.pm index c016be924..92e22b803 100644 --- a/cloud/docker/restapi/mode/nodestatus.pm +++ b/cloud/docker/restapi/mode/nodestatus.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_node_status}) && $instance_mode->{option_results}->{critical_node_status} ne '' && - eval "$instance_mode->{option_results}->{critical_node_status}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_node_status}) && $instance_mode->{option_results}->{warning_node_status} ne '' && - eval "$instance_mode->{option_results}->{warning_node_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) = @_; @@ -82,7 +57,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, } }, ]; @@ -136,8 +111,7 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_node_status', 'critical_node_status']); } sub prefix_node_output { @@ -146,16 +120,6 @@ sub prefix_node_output { return "Node '" . $options{instance_value}->{display} . "' "; } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_node_status', 'critical_node_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/ibm/softlayer/mode/events.pm b/cloud/ibm/softlayer/mode/events.pm index 168773eb5..1f3fb792a 100644 --- a/cloud/ibm/softlayer/mode/events.pm +++ b/cloud/ibm/softlayer/mode/events.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use DateTime; - -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, debug => 1); - } - - return $status; -} +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub custom_event_output { my ($self, %options) = @_; @@ -133,7 +108,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_event_calc'), closure_custom_output => $self->can('custom_event_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -159,18 +134,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 manage_selection { diff --git a/cloud/ibm/softlayer/mode/opentickets.pm b/cloud/ibm/softlayer/mode/opentickets.pm index 6a95f087d..14e95ea75 100644 --- a/cloud/ibm/softlayer/mode/opentickets.pm +++ b/cloud/ibm/softlayer/mode/opentickets.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use DateTime; - -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_ticket_output { my ($self, %options) = @_; @@ -108,7 +83,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_ticket_calc'), closure_custom_output => $self->can('custom_ticket_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -134,18 +109,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 manage_selection { diff --git a/cloud/microsoft/office365/management/mode/servicestatus.pm b/cloud/microsoft/office365/management/mode/servicestatus.pm index 4b6ddd1d7..5fdd1effa 100644 --- a/cloud/microsoft/office365/management/mode/servicestatus.pm +++ b/cloud/microsoft/office365/management/mode/servicestatus.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) = @_; @@ -91,7 +66,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, } }, ]; @@ -101,7 +76,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, } }, ]; @@ -124,22 +99,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']); } sub manage_selection { diff --git a/cloud/nutanix/snmp/mode/clusterusage.pm b/cloud/nutanix/snmp/mode/clusterusage.pm index 4742ab7cf..47ed893e0 100644 --- a/cloud/nutanix/snmp/mode/clusterusage.pm +++ b/cloud/nutanix/snmp/mode/clusterusage.pm @@ -25,34 +25,10 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); -my $instance_mode; my $cluster_name = ''; -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; -} - sub custom_status_output { my ($self, %options) = @_; @@ -73,12 +49,12 @@ sub custom_usage_perfdata { my $label = 'used'; my $value_perf = $self->{result_values}->{used}; - if (defined($instance_mode->{option_results}->{free})) { + if (defined($self->{instance_mode}->{option_results}->{free})) { $label = 'free'; $value_perf = $self->{result_values}->{free}; } my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -95,10 +71,10 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); - if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); return $exit; @@ -143,7 +119,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 => 'usage', set => { @@ -196,18 +172,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_cluster_output { diff --git a/cloud/nutanix/snmp/mode/diskusage.pm b/cloud/nutanix/snmp/mode/diskusage.pm index 99d6165ef..391294653 100644 --- a/cloud/nutanix/snmp/mode/diskusage.pm +++ b/cloud/nutanix/snmp/mode/diskusage.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; - -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) = @_; @@ -72,14 +47,14 @@ sub custom_usage_perfdata { my $label = 'used'; my $value_perf = $self->{result_values}->{used}; - if (defined($instance_mode->{option_results}->{free})) { + if (defined($self->{instance_mode}->{option_results}->{free})) { $label = 'free'; $value_perf = $self->{result_values}->{free}; } my $extra_label = ''; $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -96,10 +71,10 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); - if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); return $exit; @@ -144,7 +119,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 => 'usage', set => { @@ -207,18 +182,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_disk_output { diff --git a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm b/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm index 2a896cbb9..9afad05f3 100644 --- a/cloud/prometheus/direct/kubernetes/mode/containerstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/containerstatus.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) = @_; @@ -90,7 +65,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 => 'restarts-count', set => { @@ -162,18 +137,7 @@ sub check_options { $self->{extra_filter} .= ',' . $filter; } - $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 manage_selection { diff --git a/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm b/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm index 6b7693999..6a18dd615 100644 --- a/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/daemonsetstatus.pm @@ -24,8 +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 custom_status_perfdata { my ($self, %options) = @_; @@ -51,30 +50,6 @@ sub custom_status_perfdata { value => $self->{result_values}->{misscheduled}); } -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; -} - sub custom_status_output { my ($self, %options) = @_; @@ -119,7 +94,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => $self->can('custom_status_perfdata'), - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -181,18 +156,7 @@ sub check_options { $self->{extra_filter} .= ',' . $filter; } - $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 manage_selection { diff --git a/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm b/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm index f3ef8fd6e..f7693d04d 100644 --- a/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/deploymentstatus.pm @@ -24,8 +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 custom_status_perfdata { my ($self, %options) = @_; @@ -47,30 +46,6 @@ sub custom_status_perfdata { value => $self->{result_values}->{up_to_date}); } -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; -} - sub custom_status_output { my ($self, %options) = @_; @@ -110,7 +85,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => $self->can('custom_status_perfdata'), - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -170,18 +145,7 @@ sub check_options { $self->{extra_filter} .= ',' . $filter; } - $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 manage_selection { diff --git a/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm b/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm index 29b4911dc..a29b3ca5d 100644 --- a/cloud/prometheus/direct/kubernetes/mode/namespacestatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/namespacestatus.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) = @_; @@ -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, } }, ]; @@ -169,18 +144,7 @@ sub check_options { $self->{extra_filter} .= ',' . $filter; } - $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 manage_selection { diff --git a/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm b/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm index 323c1051d..8ec144f4c 100644 --- a/cloud/prometheus/direct/kubernetes/mode/nodestatus.pm +++ b/cloud/prometheus/direct/kubernetes/mode/nodestatus.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) = @_; @@ -77,7 +52,7 @@ sub custom_usage_perfdata { my $extra_label = ''; $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{capacity}; $total_options{cast_int} = 1; } @@ -94,7 +69,7 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{allocated}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_allocated}; } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, @@ -137,7 +112,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 => 'allocated-pods', set => { @@ -205,18 +180,7 @@ sub check_options { $self->{extra_filter} .= ',' . $filter; } - $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 manage_selection { diff --git a/cloud/prometheus/restapi/mode/expression.pm b/cloud/prometheus/restapi/mode/expression.pm index d9e540370..3e62f3478 100644 --- a/cloud/prometheus/restapi/mode/expression.pm +++ b/cloud/prometheus/restapi/mode/expression.pm @@ -24,8 +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 custom_status_perfdata { my ($self, %options) = @_; @@ -35,40 +34,16 @@ sub custom_status_perfdata { $extra_label .= '_' . $self->{result_values}->{instance}; } - foreach my $key (@{$instance_mode->{custom_keys}}) { + foreach my $key (@{$self->{instance_mode}->{custom_keys}}) { $self->{output}->perfdata_add(label => $key . $extra_label, value => $self->{result_values}->{$key}); } } -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; -} - sub custom_status_output { my ($self, %options) = @_; - my $msg = $instance_mode->{option_results}->{output}; + my $msg = $self->{instance_mode}->{option_results}->{output}; while ($msg =~ /%\{(.*?)\}/g) { my $key = $1; if (defined($self->{result_values}->{$key})) { @@ -83,7 +58,7 @@ sub custom_status_calc { my ($self, %options) = @_; $self->{result_values}->{instance} = $options{new_datas}->{$self->{instance} . '_instance'}; - foreach my $key (@{$instance_mode->{custom_keys}}) { + foreach my $key (@{$self->{instance_mode}->{custom_keys}}) { $self->{result_values}->{$key} = $options{new_datas}->{$self->{instance} . '_' . $key}; } @@ -104,7 +79,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => $self->can('custom_status_perfdata'), - closure_custom_threshold_check => $self->can('custom_status_threshold'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -172,18 +147,7 @@ sub check_options { $self->{prom_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{prom_step} = defined($self->{option_results}->{step}) ? $self->{option_results}->{step} : "1m"; - $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 manage_selection { diff --git a/cloud/prometheus/restapi/mode/targetstatus.pm b/cloud/prometheus/restapi/mode/targetstatus.pm index 1c39b4797..5c2df430b 100644 --- a/cloud/prometheus/restapi/mode/targetstatus.pm +++ b/cloud/prometheus/restapi/mode/targetstatus.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) = @_; @@ -145,7 +120,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, } }, ]; @@ -176,18 +151,7 @@ sub check_options { $self->{filters}->{$1} = $2; } - $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 manage_selection { diff --git a/database/oracle/mode/datafilesstatus.pm b/database/oracle/mode/datafilesstatus.pm index 2d2d71139..9d4c3c53b 100644 --- a/database/oracle/mode/datafilesstatus.pm +++ b/database/oracle/mode/datafilesstatus.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); sub set_counters { my ($self, %options) = @_; @@ -38,7 +39,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 => 'online-status', threshold => 0, set => { @@ -46,38 +47,12 @@ sub set_counters { closure_custom_calc => $self->can('custom_online_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, } }, ]; } -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_' . $self->{result_values}->{label_th}}) && $instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label_th}} ne '' && - eval "$instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label_th}}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label_th}}) && $instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label_th}} ne '' && - eval "$instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label_th}}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} - sub custom_status_output { my ($self, %options) = @_; my $msg = $self->{result_values}->{label_display} . ' : ' . $self->{result_values}->{$self->{result_values}->{label_th}}; @@ -127,18 +102,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', 'warning_online_status', 'critical_online_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } + $self->change_macros(macros => ['warning_status', 'critical_status', 'warning_online_status', 'critical_online_status')]); } sub prefix_df_output { diff --git a/database/oracle/mode/longqueries.pm b/database/oracle/mode/longqueries.pm index 9c629b7e7..f9b001ef7 100644 --- a/database/oracle/mode/longqueries.pm +++ b/database/oracle/mode/longqueries.pm @@ -26,32 +26,7 @@ use strict; use warnings; use centreon::plugins::misc; use centreon::plugins::statefile; - -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) = @_; @@ -88,7 +63,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, } }, ]; @@ -118,8 +93,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']); if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->check_options(%options); } @@ -129,16 +103,6 @@ sub check_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 manage_selection { my ($self, %options) = @_; $self->{sql} = $options{sql}; diff --git a/os/linux/local/mode/mountpoint.pm b/os/linux/local/mode/mountpoint.pm index fb536e99d..245101f3a 100644 --- a/os/linux/local/mode/mountpoint.pm +++ b/os/linux/local/mode/mountpoint.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; - -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) = @_; @@ -87,7 +62,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, } }, ]; @@ -125,18 +100,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 manage_selection { @@ -261,4 +225,4 @@ Threshold critical =back -=cut \ No newline at end of file +=cut diff --git a/os/linux/local/mode/systemdscstatus.pm b/os/linux/local/mode/systemdscstatus.pm index a8bc56094..b46ac99d1 100644 --- a/os/linux/local/mode/systemdscstatus.pm +++ b/os/linux/local/mode/systemdscstatus.pm @@ -25,32 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; - -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) = @_; @@ -121,7 +96,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, } }, ]; @@ -157,8 +132,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_sc_output { @@ -167,16 +141,6 @@ sub prefix_sc_output { return "Service '" . $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; - } - } -} - sub manage_selection { my ($self, %options) = @_; diff --git a/os/windows/local/mode/pendingreboot.pm b/os/windows/local/mode/pendingreboot.pm index 3a7ad91e2..acbe652db 100644 --- a/os/windows/local/mode/pendingreboot.pm +++ b/os/windows/local/mode/pendingreboot.pm @@ -26,32 +26,7 @@ use strict; use warnings; use centreon::plugins::misc; use centreon::common::powershell::windows::pendingreboot; - -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) = @_; @@ -91,7 +66,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, } }, ]; @@ -121,18 +96,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 manage_selection { diff --git a/snmp_standard/mode/spanningtree.pm b/snmp_standard/mode/spanningtree.pm index 844da61a1..f929dad3c 100644 --- a/snmp_standard/mode/spanningtree.pm +++ b/snmp_standard/mode/spanningtree.pm @@ -24,30 +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 +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, } }, ]; @@ -107,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']); } diff --git a/snmp_standard/mode/vrrp.pm b/snmp_standard/mode/vrrp.pm index 82483ff7b..fd6a326ac 100644 --- a/snmp_standard/mode/vrrp.pm +++ b/snmp_standard/mode/vrrp.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) = @_; @@ -88,7 +63,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, } }, ]; @@ -119,18 +94,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_state = (1 => 'up', 2 => 'down'); @@ -189,4 +153,4 @@ Can used special variables like: %{adminState}, %{operStateLast}, %{operState}, =back =cut - \ No newline at end of file +