diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:15:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:15:40 +0000 |
commit | b7fd908d538ed19fe41f03c0a3f93351d8da64e9 (patch) | |
tree | 46e14f318948cd4f5d7e874f83e7dfcc5d42fc64 /library/Businessprocess/ServiceNode.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-businessprocess-upstream.tar.xz icingaweb2-module-businessprocess-upstream.zip |
Adding upstream version 2.5.0.upstream/2.5.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Businessprocess/ServiceNode.php')
-rw-r--r-- | library/Businessprocess/ServiceNode.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/library/Businessprocess/ServiceNode.php b/library/Businessprocess/ServiceNode.php new file mode 100644 index 0000000..c80b984 --- /dev/null +++ b/library/Businessprocess/ServiceNode.php @@ -0,0 +1,95 @@ +<?php + +namespace Icinga\Module\Businessprocess; + +use Icinga\Module\Businessprocess\Web\Url; +use ipl\I18n\Translation; + +class ServiceNode extends MonitoredNode +{ + use Translation; + + protected $hostname; + + /** @var string Alias of the host */ + protected $hostAlias; + + protected $service; + + protected $className = 'service'; + + protected $icon = 'gear'; + + public function __construct($object) + { + $this->name = BpConfig::joinNodeName($object->hostname, $object->service); + $this->hostname = $object->hostname; + $this->service = $object->service; + if (isset($object->state)) { + $this->setState($object->state); + } else { + $this->setState(0)->setMissing(); + } + } + + public function getHostname() + { + return $this->hostname; + } + + /** + * Get the host alias + * + * @return string + */ + public function getHostAlias() + { + return $this->hostAlias; + } + + /** + * Set the host alias + * + * @param string $hostAlias + * + * @return $this + */ + public function setHostAlias($hostAlias) + { + $this->hostAlias = $hostAlias; + + return $this; + } + + public function getServiceDescription() + { + return $this->service; + } + + public function getAlias() + { + if ($this->getHostAlias() === null || $this->alias === null) { + return null; + } + + return sprintf( + $this->translate('%s on %s', '<service> on <host>'), + $this->alias, + $this->getHostAlias() + ); + } + + public function getUrl() + { + $params = array( + 'host' => $this->getHostname(), + 'service' => $this->getServiceDescription() + ); + + if ($this->getBpConfig()->hasBackendName()) { + $params['backend'] = $this->getBpConfig()->getBackendName(); + } + + return Url::fromPath('businessprocess/service/show', $params); + } +} |