From c0a8c49d4f11b1fd11d0199f2b0c8f7cfdcb81f7 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 6 Oct 2016 16:29:50 +0000 Subject: [PATCH] show/activitylog: fallback rendering for hosts... ...with obsolete parents, that have been removed in the meantime --- application/controllers/ShowController.php | 4 ++++ library/Director/Objects/IcingaHost.php | 5 +++++ library/Director/Objects/IcingaObject.php | 16 +++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php index f533d27a..8d267888 100644 --- a/application/controllers/ShowController.php +++ b/application/controllers/ShowController.php @@ -77,6 +77,10 @@ class ShowController extends ActionController protected function getObjectConfig($object) { $config = new IcingaConfig($this->db()); + if ($object->isExternal()) { + $object->object_type = 'object'; + } + $object->renderToConfig($config); return $config; } diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php index 5d885809..e8cd776a 100644 --- a/library/Director/Objects/IcingaHost.php +++ b/library/Director/Objects/IcingaHost.php @@ -110,6 +110,7 @@ class IcingaHost extends IcingaObject } $hostVars = array(); + if ($connection !== null) { foreach ($connection->fetchDistinctHostVars() as $var) { if ($var->datatype) { @@ -167,6 +168,10 @@ class IcingaHost extends IcingaObject return; } + if ($this->getRenderingZone($config) === self::RESOLVE_ERROR) { + return; + } + if ($this->getResolvedProperty('has_agent') !== 'y') { return; } diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index d1854d79..bb19d8aa 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -16,6 +16,8 @@ use Exception; abstract class IcingaObject extends DbObject implements IcingaConfigRenderer { + const RESOLVE_ERROR = '(unable to resolve)'; + protected $keyName = 'object_name'; protected $autoincKeyName = 'id'; @@ -1295,9 +1297,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer public function getRenderingZone(IcingaConfig $config = null) { - if ($zoneId = $this->getResolvedProperty('zone_id')) { - // Config has a lookup cache, is faster: - return $config->getZoneName($zoneId); + if ($this->hasUnresolvedRelatedProperty('zone_id')) { + return $this->zone; + } + + try { + if ($zoneId = $this->getResolvedProperty('zone_id')) { + // Config has a lookup cache, is faster: + return $config->getZoneName($zoneId); + } + } catch (Exception $e) { + return self::RESOLVE_ERROR; } if ($this->prefersGlobalZone()) {