From 0dbd4eb496459b0d21b01c2e41b95ee27319c983 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 14 Jan 2015 10:58:36 +0100 Subject: [PATCH 1/6] Web\Hook: support hook base classes in modules refs #8207 --- library/Icinga/Web/Hook.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Web/Hook.php b/library/Icinga/Web/Hook.php index 01d1e0e2c..7ace738d7 100644 --- a/library/Icinga/Web/Hook.php +++ b/library/Icinga/Web/Hook.php @@ -113,6 +113,18 @@ class Hook return $instance; } + protected static function splitHookName($name) + { + $sep = '\\'; + if (false === $module = strpos($name, $sep)) { + return array(null, $name); + } + return array( + substr($name, 0, $module), + substr($name, $module + 1) + ); + } + /** * Test for a valid class name * @@ -123,10 +135,24 @@ class Hook */ private static function assertValidHook($instance, $name) { - $base_class = self::$BASE_NS . ucfirst($name) . 'Hook'; + $suffix = self::$classSuffix; // 'Hook' + $base = self::$BASE_NS; // 'Icinga\\Web\\Hook\\' - if (strpos($base_class, self::$classSuffix) === false) { - $base_class .= self::$classSuffix; + list($module, $name) = self::splitHookName($name); + + if ($module === null) { + $base_class = $base . ucfirst($name) . 'Hook'; + + // I'm unsure whether this makes sense. Unused and Wrong. + if (strpos($base_class, $suffix) === false) { + $base_class .= $suffix; + } + } else { + $base_class = 'Icinga\\Module\\' + . ucfirst($module) + . '\\Web\\Hook\\' + . ucfirst($name) + . $suffix; } if (!$instance instanceof $base_class) { From 5e4b611860da8365b47d2ab750851a426b2f2fd1 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 14 Jan 2015 11:00:26 +0100 Subject: [PATCH 2/6] HostActionsHook: initial very simple implementation refs #8208 --- .../library/Monitoring/Web/Hook/HostActionsHook.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Web/Hook/HostActionsHook.php diff --git a/modules/monitoring/library/Monitoring/Web/Hook/HostActionsHook.php b/modules/monitoring/library/Monitoring/Web/Hook/HostActionsHook.php new file mode 100644 index 000000000..c1ccdfbca --- /dev/null +++ b/modules/monitoring/library/Monitoring/Web/Hook/HostActionsHook.php @@ -0,0 +1,10 @@ + Date: Wed, 14 Jan 2015 11:01:39 +0100 Subject: [PATCH 3/6] HostController: use host actions hook refs #8208 --- .../application/controllers/HostController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index ab62c3756..2f3eedf30 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -9,6 +9,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm; use Icinga\Module\Monitoring\Object\Host; use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController; +use Icinga\Web\Hook; class Monitoring_HostController extends MonitoredObjectController { @@ -33,12 +34,26 @@ class Monitoring_HostController extends MonitoredObjectController $this->createTabs(); } + protected function getHostActions() + { + $urls = array(); + + foreach (Hook::all('Monitoring\\HostActions') as $hook) { + foreach ($hook->getActionsForHost($this->object) as $id => $url) { + $urls[$id] = $url; + } + } + + return $urls; + } + /** * Show a host */ public function showAction() { $this->getTabs()->activate('host'); + $this->view->hostActions = $this->getHostActions(); parent::showAction(); } From 0d3131fbd0335f6b8aa627b85057349347946530 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 14 Jan 2015 11:02:06 +0100 Subject: [PATCH 4/6] host/show: show action urls above perfdata --- modules/monitoring/application/views/scripts/host/show.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/host/show.phtml b/modules/monitoring/application/views/scripts/host/show.phtml index 8023c1821..02f49b561 100644 --- a/modules/monitoring/application/views/scripts/host/show.phtml +++ b/modules/monitoring/application/views/scripts/host/show.phtml @@ -13,9 +13,9 @@ render('show/components/notifications.phtml') ?> render('show/components/downtime.phtml') ?> render('show/components/flapping.phtml') ?> + render('show/components/actions.phtml') ?> render('show/components/perfdata.phtml') ?> render('show/components/checksource.phtml') ?> - render('show/components/actions.phtml') ?> render('show/components/command.phtml') ?> render('show/components/hostgroups.phtml') ?> render('show/components/contacts.phtml') ?> From 0fa31acf5fb89ea25addbc578768058f30c4dbda Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 14 Jan 2015 11:02:43 +0100 Subject: [PATCH 5/6] components/actions: show host action urls if given --- .../views/scripts/show/components/actions.phtml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/monitoring/application/views/scripts/show/components/actions.phtml b/modules/monitoring/application/views/scripts/show/components/actions.phtml index 9f3211bd3..c34141084 100644 --- a/modules/monitoring/application/views/scripts/show/components/actions.phtml +++ b/modules/monitoring/application/views/scripts/show/components/actions.phtml @@ -6,6 +6,7 @@ if (! $object->action_url && ! $object->notes_url) { $links = array(); $linkText = '%s'; +$localLinkText = '%s'; if ($object->notes_url) { if (strpos($object->notes_url, "' ") === false) { @@ -32,6 +33,12 @@ if ($object->action_url) { } } +if (isset($this->hostActions)) { + foreach ($this->hostActions as $id => $action) { + $links[] = sprintf($localLinkText, $action, $id); + } +} + ?> Foreign URLs From b5cddc0a4f246c0887c544bcb5ecfd69419de227 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 14 Jan 2015 11:50:03 +0100 Subject: [PATCH 6/6] components/actions: show links if available Now we show links regardless of whether we have host actions, there might be hook-provided links only. Renamed "Foreign URLs" to "Actions" and made it translatable. --- .../views/scripts/show/components/actions.phtml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/application/views/scripts/show/components/actions.phtml b/modules/monitoring/application/views/scripts/show/components/actions.phtml index c34141084..1d926b33a 100644 --- a/modules/monitoring/application/views/scripts/show/components/actions.phtml +++ b/modules/monitoring/application/views/scripts/show/components/actions.phtml @@ -1,9 +1,5 @@ action_url && ! $object->notes_url) { - return; -} - $links = array(); $linkText = '%s'; $localLinkText = '%s'; @@ -39,8 +35,12 @@ if (isset($this->hostActions)) { } } +if (empty($links)) { + return; +} + ?> - Foreign URLs + translate('Actions') ?>