diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/Map/ProvidedHook/CubeLinks.php | 36 | ||||
-rw-r--r-- | library/Map/ProvidedHook/Monitoring/HostActions.php | 30 | ||||
-rw-r--r-- | library/Map/ProvidedHook/Monitoring/ServiceActions.php | 28 |
3 files changed, 94 insertions, 0 deletions
diff --git a/library/Map/ProvidedHook/CubeLinks.php b/library/Map/ProvidedHook/CubeLinks.php new file mode 100644 index 0000000..5f819b4 --- /dev/null +++ b/library/Map/ProvidedHook/CubeLinks.php @@ -0,0 +1,36 @@ +<?php + +namespace Icinga\Module\Map\ProvidedHook; + +use Icinga\Data\Filter\Filter; +use Icinga\Module\Cube\Cube; +use Icinga\Module\Cube\Hook\ActionsHook; +use Icinga\Module\Cube\Ido\IdoHostStatusCube; +use Icinga\Web\View; + +class CubeLinks extends ActionsHook +{ + /** + * @inheritdoc + */ + public function prepareActionLinks(Cube $cube, View $view) + { + if (! $cube instanceof IdoHostStatusCube) { + return; + } + + $vars = array("objectType"=>"host"); + foreach ($cube->getSlices() as $key => $val) { + $vars['_host_' . $key] = $val; + } + + $url = 'map'; + + $this->addActionLink( + $this->makeUrl($url, $vars), + $view->translate('Show on map'), + $view->translate('This shows all matching hosts and their current state on the map module'), + 'globe' + ); + } +} diff --git a/library/Map/ProvidedHook/Monitoring/HostActions.php b/library/Map/ProvidedHook/Monitoring/HostActions.php new file mode 100644 index 0000000..d64f743 --- /dev/null +++ b/library/Map/ProvidedHook/Monitoring/HostActions.php @@ -0,0 +1,30 @@ +<?php + +namespace Icinga\Module\Map\ProvidedHook\Monitoring; + +use Icinga\Module\Monitoring\DataView\Customvar; +use Icinga\Web\Controller\ModuleActionController; +use Icinga\Module\Monitoring\Hook\HostActionsHook; +use Icinga\Module\Monitoring\Object\Host; +use Icinga\Web\Navigation\Navigation; +use Icinga\Web\Navigation\NavigationItem; +use Icinga\Web\Url; + +class HostActions extends HostActionsHook +{ + public function getActionsForHost(Host $host) + { + $nav = new Navigation(); + + $host->fetchCustomvars(); + if (array_key_exists("geolocation", $host->customvars)) { + $nav->addItem(new NavigationItem(t('Show on map'), array( + 'url' => Url::fromPath('map/', array('showHost' => $host->getName())), + 'target' => '_next', + 'icon' => 'globe', + ))); + } + + return $nav; + } +} diff --git a/library/Map/ProvidedHook/Monitoring/ServiceActions.php b/library/Map/ProvidedHook/Monitoring/ServiceActions.php new file mode 100644 index 0000000..e29140d --- /dev/null +++ b/library/Map/ProvidedHook/Monitoring/ServiceActions.php @@ -0,0 +1,28 @@ +<?php + +namespace Icinga\Module\Map\ProvidedHook\Monitoring; + +use Icinga\Module\Monitoring\Hook\ServiceActionsHook; +use Icinga\Module\Monitoring\Object\Service; +use Icinga\Web\Navigation\Navigation; +use Icinga\Web\Navigation\NavigationItem; +use Icinga\Web\Url; + +class ServiceActions extends ServiceActionsHook +{ + public function getActionsForService(Service $service) + { + $nav = new Navigation(); + + $service->fetchCustomvars(); + if (array_key_exists("geolocation", $service->customvars)) { + $nav->addItem(new NavigationItem(t('Show on map'), array( + 'url' => Url::fromPath('map/', array('showHost' => $service->host_name . "!" . $service->getName())), + 'target' => '_next', + 'icon' => 'globe', + ))); + } + + return $nav; + } +} |