From 09cb5ef6fe3e69d6f97835587073e1b91c9d4afe Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 25 Feb 2020 16:04:40 +0100 Subject: [PATCH 1/2] ProcessCommand: handle error as UNKNOWN fixes #256 --- application/clicommands/ProcessCommand.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/application/clicommands/ProcessCommand.php b/application/clicommands/ProcessCommand.php index 7b6fb4e..6a0158a 100644 --- a/application/clicommands/ProcessCommand.php +++ b/application/clicommands/ProcessCommand.php @@ -2,6 +2,8 @@ namespace Icinga\Module\Businessprocess\Clicommands; +use Exception; +use Icinga\Application\Logger; use Icinga\Cli\Command; use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpNode; @@ -116,14 +118,17 @@ class ProcessCommand extends Command } /** @var BpNode $node */ - $node = $bp->getNode($this->params->shift()); - MonitoringState::apply($bp); - if ($bp->hasErrors()) { - printf( - "Checking Business Process %s failed: %s\n", - $node->getAlias(), - implode("\n", $bp->getErrors()) - ); + try { + $node = $bp->getNode($this->params->shift()); + MonitoringState::apply($bp); + if ($bp->hasErrors()) { + Logger::error("Checking Business Process %s failed: %s\n"); + + exit(3); + } + } catch (Exception $err) { + Logger::error("Checking Business Process failed: " . $err->getMessage()); + exit(3); } From 1397c8a7af7c0603684d6ddba3461bce9c436849 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 26 Feb 2020 09:39:14 +0100 Subject: [PATCH 2/2] ProcessCommand:handle some other errors as UNKONWN fixes #256 --- application/clicommands/ProcessCommand.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/application/clicommands/ProcessCommand.php b/application/clicommands/ProcessCommand.php index 6a0158a..af3cc29 100644 --- a/application/clicommands/ProcessCommand.php +++ b/application/clicommands/ProcessCommand.php @@ -101,12 +101,18 @@ class ProcessCommand extends Command */ public function checkAction() { - $name = $this->params->get('config'); - if ($name === null) { - $name = $this->getFirstProcessName(); - } + try { + $name = $this->params->get('config'); + if ($name === null) { + $name = $this->getFirstProcessName(); + } - $bp = $this->storage->loadProcess($name); + $bp = $this->storage->loadProcess($name); + } catch (Exception $err) { + Logger::error("Can't access configuration '%s': %s", $name, $err->getMessage()); + + exit(3); + } if (null !== ($stateType = $this->params->get('state-type'))) { if ($stateType === 'soft') { @@ -122,12 +128,12 @@ class ProcessCommand extends Command $node = $bp->getNode($this->params->shift()); MonitoringState::apply($bp); if ($bp->hasErrors()) { - Logger::error("Checking Business Process %s failed: %s\n"); + Logger::error("Checking Business Process '%s' failed: %s\n", $name, $bp->getErrors()); exit(3); } } catch (Exception $err) { - Logger::error("Checking Business Process failed: " . $err->getMessage()); + Logger::error("Checking Business Process '%s' failed: %s", $name, $err->getMessage()); exit(3); }