diff --git a/library/Director/ProvidedHook/IcingaDbCubeLinks.php b/library/Director/ProvidedHook/IcingaDbCubeLinks.php new file mode 100644 index 000000000..b2270df02 --- /dev/null +++ b/library/Director/ProvidedHook/IcingaDbCubeLinks.php @@ -0,0 +1,100 @@ +directorDb())); + + $hosts = []; + foreach ($cube->getQuery()->getHostNames($cube->getSlices()) as $host) { + $hosts[] = $host; + } + + $count = count($hosts); + $chosenHosts = []; + if ($count === 1) { + $url = 'director/host/edit'; + if (in_array($hosts[0], $directorHosts)) { + $chosenHosts[] = $hosts[0]; + $params = array('name' => $hosts[0]); + $title = $view->translate('Modify a host'); + $description = sprintf( + $view->translate('This allows you to modify properties for "%s" (deployed from director)'), + $chosenHosts[0] + ); + } + + } else { + $params = null; + + $filter = Filter::matchAny(); + foreach ($hosts as $host) { + if (in_array($host, $directorHosts)) { + $chosenHosts[] = $host; + $filter->addFilter( + Filter::matchAny(Filter::expression('name', '=', $host)) + ); + } + } + + $url = 'director/hosts/edit?' . $filter->toQueryString(); + + if (count($chosenHosts) == 1) { + $title = $view->translate('Modify a host'); + $description = sprintf( + $view->translate('This allows you to modify properties for "%s" (deployed from director)'), + $chosenHosts[0] + ); + } else { + $title = sprintf($view->translate('Modify %d hosts'), count($chosenHosts)); + $description = $view->translate( + 'This allows you to modify properties for all chosen hosts (deployed from director) at once' + ); + } + } + + if (! (count($chosenHosts) > 0)) { + return; + } + + $this->addActionLink( + $this->makeUrl($url, $params), + $title, + $description, + 'wrench' + ); + } + + protected function directorDb() + { + $resourceName = Config::module('director')->get('db', 'resource'); + if (! $resourceName) { + return false; + } + + return Db::fromResourceName($resourceName); + } +} diff --git a/register-hooks.php b/register-hooks.php index 4c746b346..16535bce1 100644 --- a/register-hooks.php +++ b/register-hooks.php @@ -58,11 +58,13 @@ use Icinga\Module\Director\PropertyModifier\PropertyModifierUuidBinToHex; use Icinga\Module\Director\PropertyModifier\PropertyModifierXlsNumericIp; use Icinga\Module\Director\ProvidedHook\CubeLinks; +use Icinga\Module\Director\ProvidedHook\IcingaDbCubeLinks; /** @var Module $this */ $this->provideHook('monitoring/HostActions'); $this->provideHook('monitoring/ServiceActions'); $this->provideHook('cube/Actions', CubeLinks::class); +$this->provideHook('cube/Icingadb', IcingaDbCubeLinks::class); $directorHooks = [ 'director/DataType' => [