ServiceInfo: ship UUID

This commit is contained in:
Thomas Gelf 2022-07-11 10:05:22 +02:00
parent 6d5c48125e
commit 4a4e540700
6 changed files with 88 additions and 15 deletions

View File

@ -7,6 +7,7 @@ use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\HostApplyMatches;
use Icinga\Module\Director\Objects\IcingaHost;
use Ramsey\Uuid\UuidInterface;
/**
* A Service Apply Rule matching this Host, generating a Service with the given
@ -23,11 +24,15 @@ class AppliedServiceInfo implements ServiceInfo
/** @var int */
protected $serviceApplyRuleId;
public function __construct($hostName, $serviceName, $serviceApplyRuleId)
/** @var UuidInterface */
protected $uuid;
public function __construct($hostName, $serviceName, $serviceApplyRuleId, UuidInterface $uuid)
{
$this->hostName = $hostName;
$this->serviceName= $serviceName;
$this->serviceApplyRuleId = $serviceApplyRuleId;
$this->uuid = $uuid;
}
public static function find(IcingaHost $host, $serviceName)
@ -36,7 +41,7 @@ class AppliedServiceInfo implements ServiceInfo
$connection = $host->getConnection();
foreach (static::fetchApplyRulesByServiceName($connection, $serviceName) as $rule) {
if ($matcher->matchesFilter($rule->filter)) {
return new static($host->getObjectName(), $serviceName, (int) $rule->id);
return new static($host->getObjectName(), $serviceName, (int) $rule->id, $rule->uuid);
}
}
@ -61,6 +66,11 @@ class AppliedServiceInfo implements ServiceInfo
return $this->serviceName;
}
public function getUuid()
{
return $this->uuid;
}
public function getUrl()
{
return Url::fromPath('director/host/appliedservice', [
@ -80,6 +90,7 @@ class AppliedServiceInfo implements ServiceInfo
$query = $db->select()
->from(['s' => 'icinga_service'], [
'id' => 's.id',
'uuid' => 's.uuid',
'name' => 's.object_name',
'assign_filter' => 's.assign_filter',
])

View File

@ -7,6 +7,7 @@ use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\HostApplyMatches;
use Icinga\Module\Director\Objects\IcingaHost;
use Ramsey\Uuid\UuidInterface;
/**
* A Service that makes part of a Service Set Apply Rule matching this Host,
@ -23,11 +24,15 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
/** @var string */
protected $serviceSetName;
public function __construct($hostName, $serviceName, $serviceSetName)
/** @var UuidInterface */
protected $uuid;
public function __construct($hostName, $serviceName, $serviceSetName, UuidInterface $uuid)
{
$this->hostName = $hostName;
$this->serviceName = $serviceName;
$this->serviceSetName = $serviceSetName;
$this->uuid = $uuid;
}
public static function find(IcingaHost $host, $serviceName)
@ -39,7 +44,8 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
return new static(
$host->getObjectName(),
$serviceName,
$rule->service_set_name
$rule->service_set_name,
$rule->uuid
);
}
}
@ -52,6 +58,11 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
return $this->hostName;
}
public function getUuid()
{
return $this->uuid;
}
/**
* @return string
*/

View File

@ -6,6 +6,7 @@ use gipfl\IcingaWeb2\Url;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
use Ramsey\Uuid\UuidInterface;
/**
* A Service attached to a parent Service Template. This is a shortcut for
@ -22,24 +23,31 @@ class InheritedServiceInfo implements ServiceInfo
/** @var string */
protected $serviceName;
public function __construct($hostName, $hostTemplateName, $serviceName)
/** @var UuidInterface */
protected $uuid;
public function __construct($hostName, $hostTemplateName, $serviceName, UuidInterface $uuid)
{
$this->hostName = $hostName;
$this->hostTemplateName = $hostTemplateName;
$this->serviceName= $serviceName;
$this->uuid = $uuid;
}
public static function find(IcingaHost $host, $serviceName)
{
$db = $host->getConnection();
foreach (IcingaTemplateRepository::instanceByObject($host)->getTemplatesFor($host, true) as $parent) {
if (IcingaService::exists([
$key = [
'host_id' => $parent->get('id'),
'object_name' => $serviceName
], $host->getConnection())) {
];
if (IcingaService::exists($key, $db)) {
return new static(
$host->getObjectName(),
$parent->getObjectName(),
$serviceName
$serviceName,
IcingaService::load($key, $db)->getUniqueId()
);
}
}
@ -52,6 +60,11 @@ class InheritedServiceInfo implements ServiceInfo
return $this->hostName;
}
public function getUuid()
{
return $this->uuid;
}
/**
* @return string
*/

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\DirectorObject\Lookup;
use gipfl\IcingaWeb2\Url;
use Icinga\Module\Director\Objects\IcingaHost;
use Ramsey\Uuid\UuidInterface;
interface ServiceInfo
{
@ -26,6 +27,11 @@ interface ServiceInfo
*/
public function getUrl();
/**
* @return UuidInterface
*/
public function getUuid();
/**
* @return bool
*/

View File

@ -5,6 +5,8 @@ namespace Icinga\Module\Director\DirectorObject\Lookup;
use gipfl\IcingaWeb2\Url;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* A service belonging to a Service Set, attached either directly to the given
@ -21,11 +23,15 @@ class ServiceSetServiceInfo implements ServiceInfo
/** @var string */
protected $serviceSetName;
public function __construct($hostName, $serviceName, $serviceSetName)
/** @var UuidInterface */
protected $uuid;
public function __construct($hostName, $serviceName, $serviceSetName, UuidInterface $uuid)
{
$this->hostName = $hostName;
$this->serviceName = $serviceName;
$this->serviceSetName = $serviceSetName;
$this->uuid = $uuid;
}
public static function find(IcingaHost $host, $serviceName)
@ -40,7 +46,10 @@ class ServiceSetServiceInfo implements ServiceInfo
$query = $db->select()
->from(
['s' => 'icinga_service'],
['service_set_name' => 'ss.object_name',]
[
'service_set_name' => 'ss.object_name',
'uuid' => 's.uuid',
]
)->join(
['ss' => 'icinga_service_set'],
's.service_set_id = ss.id',
@ -62,7 +71,12 @@ class ServiceSetServiceInfo implements ServiceInfo
);
if ($row = $db->fetchRow($query)) {
return new static($host->getObjectName(), $serviceName, $row->service_set_name);
return new static(
$host->getObjectName(),
$serviceName,
$row->service_set_name,
Uuid::fromBytes($row->uuid)
);
}
return null;
@ -78,6 +92,11 @@ class ServiceSetServiceInfo implements ServiceInfo
return $this->serviceName;
}
public function getUuid()
{
return $this->uuid;
}
/**
* @return string
*/

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\DirectorObject\Lookup;
use gipfl\IcingaWeb2\Url;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Ramsey\Uuid\UuidInterface;
/**
* A single service, directly attached to a Host Object. Overrides might
@ -21,11 +22,15 @@ class SingleServiceInfo implements ServiceInfo
/** @var bool */
protected $useOverrides;
public function __construct($hostName, $serviceName, $useOverrides)
/** @var UuidInterface */
protected $uuid;
public function __construct($hostName, $serviceName, UuidInterface $uuid, $useOverrides)
{
$this->hostName = $hostName;
$this->serviceName = $serviceName;
$this->useOverrides = $useOverrides;
$this->uuid = $uuid;
}
public static function find(IcingaHost $host, $serviceName)
@ -36,10 +41,10 @@ class SingleServiceInfo implements ServiceInfo
];
$connection = $host->getConnection();
if (IcingaService::exists($keyParams, $connection)) {
$useOverrides = IcingaService::load($keyParams, $connection)
->getResolvedVar('use_var_overrides') === 'y';
$service = IcingaService::load($keyParams, $connection);
$useOverrides = $service->getResolvedVar('use_var_overrides') === 'y';
return new static($host->getObjectName(), $serviceName, $useOverrides);
return new static($host->getObjectName(), $serviceName, $service->getUniqueId(), $useOverrides);
}
return false;
@ -55,6 +60,14 @@ class SingleServiceInfo implements ServiceInfo
return $this->serviceName;
}
/**
* @return UuidInterface
*/
public function getUuid()
{
return $this->uuid;
}
public function getUrl()
{
return Url::fromPath('director/service/edit', [