Merge pull request #264 from Icinga/fix/check-command-handling-256

ProcessCommand: handle errors as UNKNOWN
This commit is contained in:
Johannes Meyer 2020-02-26 12:02:08 +01:00 committed by GitHub
commit 9835dc9c03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
@ -99,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') {
@ -116,14 +124,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", $name, $bp->getErrors());
exit(3);
}
} catch (Exception $err) {
Logger::error("Checking Business Process '%s' failed: %s", $name, $err->getMessage());
exit(3);
}