clean code and add last enhancement

This commit is contained in:
Sims24 2017-02-16 16:55:39 +01:00
parent 9f2776f1cc
commit fb647abf22
1 changed files with 16 additions and 18 deletions

View File

@ -35,18 +35,18 @@ sub custom_metric_output {
my $msg; my $msg;
my $message; my $message;
if (defined($config_data->{filters}) && defined($config_data->{filters}->{formatting})) { if (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->{filters}->{formatting}->{printf_msg}", eval "$config_data->{filters}->{formatting}->{printf_var}");
};
} elsif (defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting})) {
eval { eval {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = 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}"); $msg = sprintf("$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_msg}", eval "$config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{printf_var}");
}; };
} elsif (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}");
};
} else { } else {
eval { eval {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
@ -108,8 +108,6 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 1, message_multiple => 'Global curves are OK' },
{ name => 'metric', type => 1, message_multiple => 'Metric curves are OK' }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
@ -144,7 +142,7 @@ sub new {
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"config-file:s" => { name => 'config_file' }, "config-file:s" => { name => 'config_file' },
"json-data:s" => { name => 'json_data' }, "json-data:s" => { name => 'json_data' },
}); });
return $self; return $self;
} }
@ -155,17 +153,17 @@ sub check_options {
$instance_mode = $self; $instance_mode = $self;
if (!defined($self->{option_results}->{config_file}) && !defined($self->{option_results}->{json_data}) { if (!defined($self->{option_results}->{config_file}) && !defined($self->{option_results}->{json_data})) {
$self->{output}->add_option_msg(short_msg => "Please define --config-file or --json-data option"); $self->{output}->add_option_msg(short_msg => "Please define --config-file or --json-data option");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (-f $self->{option_results}->{config_file} && $self->{option_results}->{config_file} eq '') { if (defined($self->{option_results}->{config_file}) && $self->{option_results}->{config_file} ne '') {
$config_data = $self->parse_json_config(config => $self->{option_results}->{config_file}); $config_data = $self->parse_json_config(config => $self->{option_results}->{config_file});
} elsif (defined($self->{option_results}->{json_data}) && $self->{option_results}->{json_data} eq '') { } elsif (defined($self->{option_results}->{json_data}) && $self->{option_results}->{json_data} ne '') {
$config_data = $self->parse_json_config(config => $self->{option_results}->{json_data}; $config_data = $self->parse_json_config(config => $self->{option_results}->{json_data});
} else { } else {
$self->{output}->add_option_msg(short_msg => "Can't find plugin configuration file / Cannot read from --json-data option"); $self->{output}->add_option_msg(short_msg => "Can't find plugin configuration file / Cannot read from --json-data option");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (!exists($config_data->{selection}) && !exists($config_data->{filters})) { if (!exists($config_data->{selection}) && !exists($config_data->{filters})) {