From 696040782529ae9cce4f63a9ca802ec57ddddfb0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 18 Jan 2021 16:03:04 +0100 Subject: [PATCH] ServiceInfo: provide requiresOverrides() --- .../Lookup/AppliedServiceInfo.php | 5 ++++ .../Lookup/AppliedServiceSetServiceInfo.php | 5 ++++ .../Lookup/InheritedServiceInfo.php | 5 ++++ .../DirectorObject/Lookup/ServiceInfo.php | 5 ++++ .../Lookup/ServiceSetServiceInfo.php | 5 ++++ .../Lookup/SingleServiceInfo.php | 24 +++++++++++++++---- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php b/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php index f25c4079..744952e5 100644 --- a/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php @@ -65,6 +65,11 @@ class AppliedServiceInfo implements ServiceInfo ]); } + public function requiresOverrides() + { + return true; + } + protected static function fetchApplyRulesByServiceName(Db $connection, $serviceName) { $db = $connection->getDbAdapter(); diff --git a/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php b/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php index 56eb8ab1..b7840a3b 100644 --- a/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php @@ -66,6 +66,11 @@ class AppliedServiceSetServiceInfo implements ServiceInfo ]); } + public function requiresOverrides() + { + return true; + } + protected static function fetchServiceSetApplyRulesByServiceName(Db $connection, $serviceName) { $db = $connection->getDbAdapter(); diff --git a/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php b/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php index 6303086f..ede98a0f 100644 --- a/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php @@ -69,4 +69,9 @@ class InheritedServiceInfo implements ServiceInfo 'inheritedFrom' => $this->hostTemplateName ]); } + + public function requiresOverrides() + { + return true; + } } diff --git a/library/Director/DirectorObject/Lookup/ServiceInfo.php b/library/Director/DirectorObject/Lookup/ServiceInfo.php index 6379135b..4ff024df 100644 --- a/library/Director/DirectorObject/Lookup/ServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/ServiceInfo.php @@ -26,6 +26,11 @@ interface ServiceInfo */ public function getUrl(); + /** + * @return bool + */ + public function requiresOverrides(); + /** * @param IcingaHost $host * @param $serviceName diff --git a/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php b/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php index fe67a96d..ee8032be 100644 --- a/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php @@ -85,4 +85,9 @@ class ServiceSetServiceInfo implements ServiceInfo 'set' => $this->serviceSetName, ]); } + + public function requiresOverrides() + { + return true; + } } diff --git a/library/Director/DirectorObject/Lookup/SingleServiceInfo.php b/library/Director/DirectorObject/Lookup/SingleServiceInfo.php index 931ea33f..f9569014 100644 --- a/library/Director/DirectorObject/Lookup/SingleServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/SingleServiceInfo.php @@ -8,23 +8,34 @@ use Icinga\Module\Director\Objects\IcingaService; class SingleServiceInfo implements ServiceInfo { + /** @var string */ protected $hostName; + /** @var string */ protected $serviceName; - public function __construct($hostName, $serviceName) + /** @var bool */ + protected $useOverrides; + + public function __construct($hostName, $serviceName, $useOverrides) { $this->hostName = $hostName; $this->serviceName= $serviceName; + $this->useOverrides = $useOverrides; } public static function find(IcingaHost $host, $serviceName) { - if (IcingaService::exists([ + $keyParams = [ 'host_id' => $host->get('id'), 'object_name' => $serviceName - ], $host->getConnection())) { - return new static($host->getObjectName(), $serviceName); + ]; + $connection = $host->getConnection(); + if (IcingaService::exists($keyParams, $connection)) { + $useOverrides = IcingaService::load($keyParams, $connection) + ->getResolvedVar('use_var_overrides') === 'y'; + + return new static($host->getObjectName(), $serviceName, $useOverrides); } return false; @@ -47,4 +58,9 @@ class SingleServiceInfo implements ServiceInfo 'service' => $this->serviceName, ]); } + + public function requiresOverrides() + { + return $this->useOverrides; + } }