From ddb8469ee985208989094eab8a45469976495c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Starck?= Date: Fri, 6 Feb 2015 10:49:11 -0500 Subject: [PATCH] Enh: A failed action can miss its stderr output which can be very usefull for debug/investigation ofcourse. Usecase: the command exited with != 0 and only stderr output was given. --- shinken/action.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/shinken/action.py b/shinken/action.py index dee16a8d86..87a62ac737 100644 --- a/shinken/action.py +++ b/shinken/action.py @@ -209,15 +209,11 @@ def check_finished(self, max_plugins_output_length): # we should not keep the process now del self.process - # if the exit status is abnormal, we add stderr to the output - # TODO: Abnormal should be logged properly no? - if self.exit_status not in valid_exit_status: - self.stdoutdata = self.stdoutdata + self.stderrdata - elif ('sh: -c: line 0: unexpected EOF while looking for matching' - in self.stderrdata - or ('sh: -c:' in self.stderrdata and ': Syntax' in self.stderrdata) - or 'Syntax error: Unterminated quoted string' - in self.stderrdata): + if ( # check for bad syntax in command line: + 'sh: -c: line 0: unexpected EOF while looking for matching' in self.stderrdata + or ('sh: -c:' in self.stderrdata and ': Syntax' in self.stderrdata) + or 'Syntax error: Unterminated quoted string' in self.stderrdata + ): # Very, very ugly. But subprocess._handle_exitstatus does # not see a difference between a regular "exit 1" and a # bailing out shell. Strange, because strace clearly shows @@ -225,6 +221,12 @@ def check_finished(self, max_plugins_output_length): self.stdoutdata = self.stdoutdata + self.stderrdata self.exit_status = 3 + if self.exit_status not in valid_exit_status: + self.exit_status = 3 + + if not self.stdoutdata.strip(): + self.stdoutdata = self.stderrdata + # Now grep what we want in the output self.get_outputs(self.stdoutdata, max_plugins_output_length)