From d64643e575cb60af2d465d73a40ca9934da31cba Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Fri, 26 Apr 2019 18:40:51 +0200 Subject: [PATCH] add options for backtick function --- centreon-plugins/centreon/plugins/misc.pm | 37 ++++++++++++--------- centreon-plugins/cloud/aws/custom/awscli.pm | 4 ++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index 112cd9102..b59716a06 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -119,6 +119,11 @@ sub unix_execute { my $cmd = ''; my $args = []; my ($lerror, $stdout, $exit_code); + + my $redirect_stderr = 1; + $redirect_stderr = $options{redirect_stderr} if (defined($options{redirect_stderr})); + my $wait_exit = 1; + $wait_exit = $options{wait_exit} if (defined($options{wait_exit})); # Build command line # Can choose which command is done remotely (can filter and use local file) @@ -149,19 +154,19 @@ sub unix_execute { if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) { $cmd = "echo '" . $sub_cmd . "' | " . $cmd . ' ' . join(" ", @$args); ($lerror, $stdout, $exit_code) = backtick( - command => $cmd, - timeout => $options{options}->{timeout}, - wait_exit => 1, - redirect_stderr => 1 - ); + command => $cmd, + timeout => $options{options}->{timeout}, + wait_exit => $wait_exit, + redirect_stderr => $redirect_stderr + ); } else { ($lerror, $stdout, $exit_code) = backtick( - command => $cmd, - arguments => [@$args, $sub_cmd], - timeout => $options{options}->{timeout}, - wait_exit => 1, - redirect_stderr => 1 - ); + command => $cmd, + arguments => [@$args, $sub_cmd], + timeout => $options{options}->{timeout}, + wait_exit => $wait_exit, + redirect_stderr => $redirect_stderr + ); } } else { $cmd = 'sudo ' if (defined($options{sudo})); @@ -170,11 +175,11 @@ sub unix_execute { $cmd .= $options{command_options} if (defined($options{command_options})); ($lerror, $stdout, $exit_code) = backtick( - command => $cmd, - timeout => $options{options}->{timeout}, - wait_exit => 1, - redirect_stderr => 1 - ); + command => $cmd, + timeout => $options{options}->{timeout}, + wait_exit => $wait_exit, + redirect_stderr => $redirect_stderr + ); } if (defined($options{options}->{show_output}) && diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index 04f0b43f8..c86e59b4f 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -132,7 +132,9 @@ sub execute { sudo => $self->{option_results}->{sudo}, command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, - command_options => $options{cmd_options}); + command_options => $options{cmd_options}, + redirect_stderr => 0 + ); my $raw_results;