From 20d3eb1e1e7182e24bf3d20f19f01a34421359d4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 16 Oct 2015 22:48:57 +0200 Subject: [PATCH] ImportedNode: gracefully handle missing files --- library/Businessprocess/ImportedNode.php | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/library/Businessprocess/ImportedNode.php b/library/Businessprocess/ImportedNode.php index aedcf86..f829b92 100644 --- a/library/Businessprocess/ImportedNode.php +++ b/library/Businessprocess/ImportedNode.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Businessprocess; use Icinga\Application\Config; use Icinga\Web\Url; use Icinga\Module\Businessprocess\Storage\LegacyStorage; +use Exception; class ImportedNode extends Node { @@ -74,14 +75,31 @@ class ImportedNode extends Node $storage = new LegacyStorage( Config::module('businessprocess')->getSection('global') ); - $this->importedBp = $storage->loadProcess($this->configName); - if ($this->bp->usesSoftStates()) { - $this->importedBp->useSoftStates(); - } else { - $this->importedBp->useHardStates(); + try { + $this->importedBp = $storage->loadProcess($this->configName); + if ($this->bp->usesSoftStates()) { + $this->importedBp->useSoftStates(); + } else { + $this->importedBp->useHardStates(); + } + $this->importedBp->retrieveStatesFromBackend(); + $this->importedNode = $this->importedBp->getNode($this->name); + } catch (Exception $e) { + + + $node = new BpNode($this->bp, (object) array( + 'name' => $this->name, + 'operator' => '&', + 'child_names' => array() + )); + $node->setState(2); + $node->setMissing(false) + ->setDowntime(false) + ->setAck(false) + ->setAlias($e->getMessage()); + + $this->importedNode = $node; } - $this->importedBp->retrieveStatesFromBackend(); - $this->importedNode = $this->importedBp->getNode($this->name); } return $this->importedNode; }