From 9f2776f1cc495f357f5b714a473a8d56d939c69e Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 16 Feb 2017 13:21:18 +0100 Subject: [PATCH] Add possibility to override global formatting definition --- apps/centreon/sql/mode/virtualservice.pm | 27 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/centreon/sql/mode/virtualservice.pm b/apps/centreon/sql/mode/virtualservice.pm index a811013c2..4a276565f 100644 --- a/apps/centreon/sql/mode/virtualservice.pm +++ b/apps/centreon/sql/mode/virtualservice.pm @@ -35,18 +35,33 @@ sub custom_metric_output { my $msg; my $message; - eval { - local $SIG{__WARN__} = sub { $message = $_[0]; }; - local $SIG{__DIE__} = sub { $message = $_[0]; }; - - $msg = sprintf("$config_data->{formatting}->{printf_msg}", eval "$config_data->{formatting}->{printf_var}"); - }; + if (defined($config_data->{filters}) && defined($config_data->{filters}->{formatting})) { + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + $msg = sprintf("$config_data->{filters}->{formatting}->{printf_msg}", eval "$config_data->{filters}->{formatting}->{printf_var}"); + }; + } elsif (defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting})) { + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + $msg = sprintf("$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg}", eval "$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}"); + }; + } else { + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + $msg = sprintf("$config_data->{formatting}->{printf_msg}", eval "$config_data->{formatting}->{printf_var}"); + }; + } if (defined($message)) { $self->{output}->output_add(long_msg => 'printf expression problem: ' . $message); $self->{output}->option_exit(); } + return $msg; + } sub custom_metric_calc {