From cd989f9c3aff968e19a3aeabc4eb9085787a6673 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:43:12 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/ProvidedHook/CubeLinks.php | 65 ++++++++++++++++ .../Director/ProvidedHook/IcingaDbCubeLinks.php | 66 ++++++++++++++++ .../ProvidedHook/Monitoring/HostActions.php | 73 ++++++++++++++++++ .../ProvidedHook/Monitoring/ServiceActions.php | 87 ++++++++++++++++++++++ 4 files changed, 291 insertions(+) create mode 100644 library/Director/ProvidedHook/CubeLinks.php create mode 100644 library/Director/ProvidedHook/IcingaDbCubeLinks.php create mode 100644 library/Director/ProvidedHook/Monitoring/HostActions.php create mode 100644 library/Director/ProvidedHook/Monitoring/ServiceActions.php (limited to 'library/Director/ProvidedHook') diff --git a/library/Director/ProvidedHook/CubeLinks.php b/library/Director/ProvidedHook/CubeLinks.php new file mode 100644 index 0000000..2cb9559 --- /dev/null +++ b/library/Director/ProvidedHook/CubeLinks.php @@ -0,0 +1,65 @@ +finalizeInnerQuery(); + $query = $cube->innerQuery() + ->reset('columns') + ->columns(array('host' => 'o.name1')) + ->reset('group'); + + $hosts = $cube->db()->fetchCol($query); + + $count = count($hosts); + if ($count === 1) { + $url = 'director/host/edit'; + $params = array('name' => $hosts[0]); + + $title = $view->translate('Modify a host'); + $description = sprintf( + $view->translate('This allows you to modify properties for "%s"'), + $hosts[0] + ); + } else { + $params = null; + + $filter = Filter::matchAny(); + foreach ($hosts as $host) { + $filter->addFilter( + Filter::matchAny(Filter::expression('name', '=', $host)) + ); + } + + $url = 'director/hosts/edit?' . $filter->toQueryString(); + + $title = sprintf($view->translate('Modify %d hosts'), $count); + $description = $view->translate( + 'This allows you to modify properties for all chosen hosts at once' + ); + } + + $this->addActionLink( + $this->makeUrl($url, $params), + $title, + $description, + 'wrench' + ); + } +} diff --git a/library/Director/ProvidedHook/IcingaDbCubeLinks.php b/library/Director/ProvidedHook/IcingaDbCubeLinks.php new file mode 100644 index 0000000..234f61f --- /dev/null +++ b/library/Director/ProvidedHook/IcingaDbCubeLinks.php @@ -0,0 +1,66 @@ +getObjectsFilter(); + + if ($filterChain->count() === 1) { + $url = 'director/host/edit?'; + $params = ['name' => $filterChain->getIterator()->current()->getValue()]; + + $title = t('Modify a host'); + $description = sprintf( + t('This allows you to modify properties for "%s"'), + $filterChain->getIterator()->current()->getValue() + ); + } else { + $params = null; + + $urlFilter = Filter::matchAny(); + foreach ($filterChain as $filter) { + $urlFilter->addFilter( + Filter::matchAny( + Filter::expression( + 'name', + '=', + $filter->getValue() + ) + ) + ); + } + + $url = 'director/hosts/edit?' . $urlFilter->toQueryString(); + + $title = sprintf(t('Modify %d hosts'), $filterChain->count()); + $description = t( + 'This allows you to modify properties for all chosen hosts at once' + ); + } + + $this->addActionLink( + $this->makeUrl($url, $params), + $title, + $description, + 'wrench' + ); + } +} 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 @@ +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 @@ +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); + } +} -- cgit v1.2.3