From d59da382d7dad08cc11f8c1657c0c4b2799f8da7 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 7 Feb 2019 13:41:18 +0100 Subject: [PATCH] change exit behaviour for unix/windows exec --- centreon-plugins/centreon/plugins/misc.pm | 36 +++++++-------------- centreon-plugins/centreon/plugins/output.pm | 4 ++- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index 24bcafe11..f31b8c0c8 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -51,19 +51,15 @@ sub windows_execute { $| = 1; pipe FROM_CHILD, TO_PARENT or do { - $options{output}->output_add(severity => 'UNKNOWN', - short_msg => "Internal error: can't create pipe from child to parent: $!"); - $options{output}->display(); - $options{output}->exit(); + $options{output}->add_option_msg(short_msg => "Internal error: can't create pipe from child to parent: $!"); + $options{output}->option_exit(); }; my $job = Win32::Job->new; if (!($pid = $job->spawn(undef, $cmd, { stdout => \*TO_PARENT, stderr => \*TO_PARENT }))) { - $options{output}->output_add(severity => 'UNKNOWN', - short_msg => "Internal error: execution issue: $^E"); - $options{output}->display(); - $options{output}->exit(); + $options{output}->add_option_msg(short_msg => "Internal error: execution issue: $^E"); + $options{output}->option_exit(); } close TO_PARENT; @@ -97,10 +93,8 @@ sub windows_execute { close FROM_CHILD; if ($ended == 0) { - $options{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command too long to execute (timeout)..."); - $options{output}->display(); - $options{output}->exit(); + $options{output}->add_option_msg(short_msg => "Command too long to execute (timeout)..."); + $options{output}->option_exit(); } chomp $stdout; @@ -110,10 +104,8 @@ sub windows_execute { if ($result->{$pid}->{exitcode} != 0) { $stdout =~ s/\n/ - /g; - $options{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command error: $stdout"); - $options{output}->display(); - $options{output}->exit(); + $options{output}->add_option_msg(short_msg => "Command error: $stdout"); + $options{output}->option_exit(); } return ($stdout, $result->{$pid}->{exitcode}); @@ -190,10 +182,8 @@ sub unix_execute { $stdout =~ s/\r//g; if ($lerror <= -1000) { - $options{output}->output_add(severity => 'UNKNOWN', - short_msg => $stdout); - $options{output}->display(); - $options{output}->exit(); + $options{output}->add_option_msg(short_msg => $stdout); + $options{output}->option_exit(); } if (defined($options{no_quit}) && $options{no_quit} == 1) { @@ -202,10 +192,8 @@ sub unix_execute { if ($exit_code != 0 && (!defined($options{no_errors}) || !defined($options{no_errors}->{$exit_code}))) { $stdout =~ s/\n/ - /g; - $options{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command error: $stdout"); - $options{output}->display(); - $options{output}->exit(); + $options{output}->add_option_msg(short_msg => "Command error: $stdout"); + $options{output}->option_exit(); } return $stdout; diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 509e3b597..a97cbe216 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -1060,7 +1060,9 @@ Filter UOM that match the regexp. =item B<--opt-exit> -Exit code for an option error, usage (default: unknown). +Optional exit code for an execution error (i.e. wrong option provided, +SSH connection refused, timeout, etc) +(Default: unknown). =item B<--output-xml>