diff options
Diffstat (limited to '')
-rw-r--r-- | library/Director/ProvidedHook/Monitoring/HostActions.php | 73 | ||||
-rw-r--r-- | library/Director/ProvidedHook/Monitoring/ServiceActions.php | 87 |
2 files changed, 160 insertions, 0 deletions
diff --git a/library/Director/ProvidedHook/Monitoring/HostActions.php b/library/Director/ProvidedHook/Monitoring/HostActions.php new file mode 100644 index 0000000..2e3fba0 --- /dev/null +++ b/library/Director/ProvidedHook/Monitoring/HostActions.php @@ -0,0 +1,73 @@ +<?php + +namespace Icinga\Module\Director\ProvidedHook\Monitoring; + +use Exception; +use Icinga\Application\Config; +use Icinga\Authentication\Auth; +use Icinga\Module\Director\Db; +use Icinga\Module\Director\Monitoring; +use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Module\Director\Util; +use Icinga\Module\Monitoring\Hook\HostActionsHook; +use Icinga\Module\Monitoring\Object\Host; +use Icinga\Web\Url; + +class HostActions extends HostActionsHook +{ + public function getActionsForHost(Host $host) + { + try { + return $this->getThem($host); + } catch (Exception $e) { + return array(); + } + } + + protected function getThem(Host $host) + { + $actions = array(); + $db = $this->db(); + if (! $db) { + return $actions; + } + $hostname = $host->host_name; + if (Util::hasPermission('director/inspect')) { + $actions[mt('director', 'Inspect')] = Url::fromPath( + 'director/inspect/object', + array('type' => 'host', 'plural' => 'hosts', 'name' => $hostname) + ); + } + + $allowEdit = false; + if (Util::hasPermission('director/hosts') && IcingaHost::exists($hostname, $db)) { + $allowEdit = true; + } + $auth = Auth::getInstance(); + if (Util::hasPermission('director/monitoring/hosts')) { + $monitoring = new Monitoring(); + if ($monitoring->isAvailable() && $monitoring->authCanEditHost($auth, $hostname)) { + $allowEdit = IcingaHost::exists($hostname, $db); + } + } + + if ($allowEdit) { + $actions[mt('director', 'Modify')] = Url::fromPath( + 'director/host/edit', + array('name' => $hostname) + ); + } + + return $actions; + } + + protected function db() + { + $resourceName = Config::module('director')->get('db', 'resource'); + if (! $resourceName) { + return false; + } + + return Db::fromResourceName($resourceName); + } +} diff --git a/library/Director/ProvidedHook/Monitoring/ServiceActions.php b/library/Director/ProvidedHook/Monitoring/ServiceActions.php new file mode 100644 index 0000000..b2e303a --- /dev/null +++ b/library/Director/ProvidedHook/Monitoring/ServiceActions.php @@ -0,0 +1,87 @@ +<?php + +namespace Icinga\Module\Director\ProvidedHook\Monitoring; + +use Exception; +use Icinga\Application\Config; +use Icinga\Authentication\Auth; +use Icinga\Module\Director\Db; +use Icinga\Module\Director\Monitoring; +use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Module\Director\Util; +use Icinga\Module\Monitoring\Hook\ServiceActionsHook; +use Icinga\Module\Monitoring\Object\Service; +use Icinga\Web\Url; + +class ServiceActions extends ServiceActionsHook +{ + public function getActionsForService(Service $service) + { + try { + return $this->getThem($service); + } catch (Exception $e) { + return []; + } + } + + /** + * @param Service $service + * @return array + * @throws \Icinga\Exception\ProgrammingError + */ + protected function getThem(Service $service) + { + $actions = []; + $db = $this->db(); + if (! $db) { + return []; + } + + $hostname = $service->host_name; + $serviceName = $service->service_description; + if (Util::hasPermission('director/inspect')) { + $actions[mt('director', 'Inspect')] = Url::fromPath('director/inspect/object', [ + 'type' => 'service', + 'plural' => 'services', + 'name' => sprintf( + '%s!%s', + $hostname, + $serviceName + ) + ]); + } + + $title = null; + if (Util::hasPermission('director/hosts')) { + $title = mt('director', 'Modify'); + } elseif (Util::hasPermission('director/monitoring/services')) { + $monitoring = new Monitoring(); + if ($monitoring->isAvailable() + && $monitoring->authCanEditService(Auth::getInstance(), $hostname, $serviceName) + ) { + $title = mt('director', 'Modify'); + } + } elseif (Util::hasPermission('director/monitoring/services-ro')) { + $title = mt('director', 'Configuration'); + } + + if ($title && IcingaHost::exists($hostname, $db)) { + $actions[$title] = Url::fromPath('director/host/findservice', [ + 'name' => $hostname, + 'service' => $serviceName + ]); + } + + return $actions; + } + + protected function db() + { + $resourceName = Config::module('director')->get('db', 'resource'); + if (! $resourceName) { + return false; + } + + return Db::fromResourceName($resourceName); + } +} |