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 $message;
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})) {
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->{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 {
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
@ -108,8 +108,6 @@ sub set_counters {
my ($self, %options) = @_;
$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} = [
@ -144,7 +142,7 @@ sub new {
$options{options}->add_options(arguments =>
{
"config-file:s" => { name => 'config_file' },
"json-data:s" => { name => 'json_data' },
"json-data:s" => { name => 'json_data' },
});
return $self;
}
@ -155,17 +153,17 @@ sub check_options {
$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}->option_exit();
}
if (-f $self->{option_results}->{config_file} && $self->{option_results}->{config_file} eq '') {
$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 '') {
$config_data = $self->parse_json_config(config => $self->{option_results}->{json_data};
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});
} 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});
} else {
$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})) {
@ -339,7 +337,7 @@ Specify the full path to a json config file
=item B<--filter-counters>
Filter some counter (can be 'unique' or 'global')
Useless, if you use selection/filter but not
Useless, if you use selection/filter but not
global/virtual curves
=item B<--warning-*>
@ -354,4 +352,4 @@ BE CAREFUL, will override config file definition
=back
=cut
=cut