summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/ServiceNode.php
blob: c80b9847e97af1f0a4ec8e0f5752e906fba63ea4 (plain)
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
84
85
86
87
88
89
90
91
92
93
94
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);
    }
}