1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?php
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
* still be used when use_var_overrides is true.
*/
class SingleServiceInfo implements ServiceInfo
{
/** @var string */
protected $hostName;
/** @var string */
protected $serviceName;
/** @var bool */
protected $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)
{
$keyParams = [
'host_id' => $host->get('id'),
'object_name' => $serviceName
];
$connection = $host->getConnection();
if (IcingaService::exists($keyParams, $connection)) {
$service = IcingaService::load($keyParams, $connection);
$useOverrides = $service->getResolvedVar('use_var_overrides') === 'y';
return new static($host->getObjectName(), $serviceName, $service->getUniqueId(), $useOverrides);
}
return false;
}
public function getHostName()
{
return $this->hostName;
}
public function getName()
{
return $this->serviceName;
}
/**
* @return UuidInterface
*/
public function getUuid()
{
return $this->uuid;
}
public function getUrl()
{
return Url::fromPath('director/service/edit', [
'host' => $this->hostName,
'name' => $this->serviceName,
]);
}
public function requiresOverrides()
{
return $this->useOverrides;
}
}
|