2015-07-02 15:28:41 +02:00
|
|
|
<?php
|
|
|
|
|
2015-11-20 12:41:34 +01:00
|
|
|
namespace Icinga\Module\Director\ProvidedHook\Monitoring;
|
2015-07-02 15:28:41 +02:00
|
|
|
|
2016-06-28 09:40:25 +02:00
|
|
|
use Exception;
|
2015-07-02 15:28:41 +02:00
|
|
|
use Icinga\Application\Config;
|
|
|
|
use Icinga\Module\Director\Db;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
2015-12-16 20:57:33 +01:00
|
|
|
use Icinga\Module\Monitoring\Hook\HostActionsHook;
|
2015-07-02 15:28:41 +02:00
|
|
|
use Icinga\Module\Monitoring\Object\Host;
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
|
|
|
|
class HostActions extends HostActionsHook
|
|
|
|
{
|
|
|
|
public function getActionsForHost(Host $host)
|
2016-06-28 09:40:25 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
return $this->getThem($host);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getThem(Host $host)
|
2015-07-02 15:28:41 +02:00
|
|
|
{
|
|
|
|
$db = $this->db();
|
2015-11-30 12:19:37 +01:00
|
|
|
if (! $db) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2015-07-02 15:28:41 +02:00
|
|
|
if (IcingaHost::exists($host->host_name, $db)) {
|
|
|
|
return array(
|
|
|
|
'Modify' => Url::fromPath(
|
|
|
|
'director/host/edit',
|
|
|
|
array('name' => $host->host_name)
|
2015-11-26 18:54:26 +01:00
|
|
|
),
|
|
|
|
'Inspect' => Url::fromPath(
|
|
|
|
'director/inspect/object',
|
|
|
|
array('type' => 'host', 'plural' => 'hosts', 'name' => $host->host_name)
|
2015-07-02 15:28:41 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function db()
|
|
|
|
{
|
2015-11-30 12:19:37 +01:00
|
|
|
$resourceName = Config::module('director')->get('db', 'resource');
|
|
|
|
if (! $resourceName) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Db::fromResourceName($resourceName);
|
2015-07-02 15:28:41 +02:00
|
|
|
}
|
|
|
|
}
|