ServiceInfo: provide requiresOverrides()

This commit is contained in:
Thomas Gelf 2021-01-18 16:03:04 +01:00
parent e4e96206b4
commit 6960407825
6 changed files with 45 additions and 4 deletions

View File

@ -65,6 +65,11 @@ class AppliedServiceInfo implements ServiceInfo
]); ]);
} }
public function requiresOverrides()
{
return true;
}
protected static function fetchApplyRulesByServiceName(Db $connection, $serviceName) protected static function fetchApplyRulesByServiceName(Db $connection, $serviceName)
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();

View File

@ -66,6 +66,11 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
]); ]);
} }
public function requiresOverrides()
{
return true;
}
protected static function fetchServiceSetApplyRulesByServiceName(Db $connection, $serviceName) protected static function fetchServiceSetApplyRulesByServiceName(Db $connection, $serviceName)
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();

View File

@ -69,4 +69,9 @@ class InheritedServiceInfo implements ServiceInfo
'inheritedFrom' => $this->hostTemplateName 'inheritedFrom' => $this->hostTemplateName
]); ]);
} }
public function requiresOverrides()
{
return true;
}
} }

View File

@ -26,6 +26,11 @@ interface ServiceInfo
*/ */
public function getUrl(); public function getUrl();
/**
* @return bool
*/
public function requiresOverrides();
/** /**
* @param IcingaHost $host * @param IcingaHost $host
* @param $serviceName * @param $serviceName

View File

@ -85,4 +85,9 @@ class ServiceSetServiceInfo implements ServiceInfo
'set' => $this->serviceSetName, 'set' => $this->serviceSetName,
]); ]);
} }
public function requiresOverrides()
{
return true;
}
} }

View File

@ -8,23 +8,34 @@ use Icinga\Module\Director\Objects\IcingaService;
class SingleServiceInfo implements ServiceInfo class SingleServiceInfo implements ServiceInfo
{ {
/** @var string */
protected $hostName; protected $hostName;
/** @var string */
protected $serviceName; protected $serviceName;
public function __construct($hostName, $serviceName) /** @var bool */
protected $useOverrides;
public function __construct($hostName, $serviceName, $useOverrides)
{ {
$this->hostName = $hostName; $this->hostName = $hostName;
$this->serviceName= $serviceName; $this->serviceName= $serviceName;
$this->useOverrides = $useOverrides;
} }
public static function find(IcingaHost $host, $serviceName) public static function find(IcingaHost $host, $serviceName)
{ {
if (IcingaService::exists([ $keyParams = [
'host_id' => $host->get('id'), 'host_id' => $host->get('id'),
'object_name' => $serviceName '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; return false;
@ -47,4 +58,9 @@ class SingleServiceInfo implements ServiceInfo
'service' => $this->serviceName, 'service' => $this->serviceName,
]); ]);
} }
public function requiresOverrides()
{
return $this->useOverrides;
}
} }