icingaweb2-module-director/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php

95 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\Module\Director\DirectorObject\Lookup;
use gipfl\IcingaWeb2\Url;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
2022-07-11 10:05:22 +02:00
use Ramsey\Uuid\UuidInterface;
/**
* A Service attached to a parent Service Template. This is a shortcut for
* 'assign where "Template Name" in templates'
*/
class InheritedServiceInfo implements ServiceInfo
{
/** @var string */
protected $hostName;
/** @var string */
protected $hostTemplateName;
/** @var string */
protected $serviceName;
2022-07-11 10:05:22 +02:00
/** @var UuidInterface */
protected $uuid;
public function __construct($hostName, $hostTemplateName, $serviceName, UuidInterface $uuid)
{
$this->hostName = $hostName;
$this->hostTemplateName = $hostTemplateName;
$this->serviceName= $serviceName;
2022-07-11 10:05:22 +02:00
$this->uuid = $uuid;
}
public static function find(IcingaHost $host, $serviceName)
{
2022-07-11 10:05:22 +02:00
$db = $host->getConnection();
foreach (IcingaTemplateRepository::instanceByObject($host)->getTemplatesFor($host, true) as $parent) {
2022-07-11 10:05:22 +02:00
$key = [
'host_id' => $parent->get('id'),
'object_name' => $serviceName
2022-07-11 10:05:22 +02:00
];
if (IcingaService::exists($key, $db)) {
return new static(
$host->getObjectName(),
$parent->getObjectName(),
2022-07-11 10:05:22 +02:00
$serviceName,
IcingaService::load($key, $db)->getUniqueId()
);
}
}
return false;
}
public function getHostName()
{
return $this->hostName;
}
2022-07-11 10:05:22 +02:00
public function getUuid()
{
return $this->uuid;
}
/**
* @return string
*/
public function getHostTemplateName()
{
return $this->hostTemplateName;
}
public function getName()
{
return $this->serviceName;
}
public function getUrl()
{
return Url::fromPath('director/host/inheritedservice', [
'name' => $this->hostName,
'service' => $this->serviceName,
'inheritedFrom' => $this->hostTemplateName
]);
}
public function requiresOverrides()
{
return true;
}
}