From 5e314cc84c252e9136483d7dd366bbe5185daaa8 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 16 Feb 2016 16:10:43 +0100 Subject: [PATCH] ShowController: add serviceAction, adjust host --- application/controllers/ShowController.php | 173 ++++++++++++++++++--- run.php | 1 + 2 files changed, 151 insertions(+), 23 deletions(-) diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php index 8c834ce..f029b81 100644 --- a/application/controllers/ShowController.php +++ b/application/controllers/ShowController.php @@ -146,29 +146,164 @@ class ShowController extends Controller public function hostAction() { + $this->handleDatasourceToggles(); + $this->handleGraphParams(); $hostname = $this->view->hostname = $this->params->get('host'); if (! $hostname) { throw new NotFoundError('Host is required'); } - $this->tabs()->activate('host'); - $hosts = $this->Config()->get('global', 'host_pattern'); + + $view = $this->view; + $this->getTabs()->add('host', array( + 'label' => $this->translate('Graphite - Single Host'), + 'url' => $this->getRequest()->getUrl() + ))->activate('host'); + $imgs = array(); - $this->view->templates = $this->loadTemplates(); + $this->view->templates = array(); - foreach ($this->view->templates as $type => $template) { + foreach ($this->templateStore->loadTemplateSets() as $setname => $set) { - $imgs[$type] = $this->graphiteWeb - ->select() - ->from( - array('host' => $hosts), - $template->getFilterString() - ) - ->where('hostname', $hostname) - ->getImages($template); + $patterns = $set->getBasePatterns(); + if (! array_key_exists('icingaHost', $patterns)) continue; - foreach ($imgs[$type] as $img) { - $this->applyGraphParams($img) - ->showLegend(! $this->params->get('hideLegend', false)); + foreach ($set->loadTemplates() as $key => $template) { + if (strpos($template->getFilterString(), '$service') !== false) continue; + + $imgParams = array( + 'template' => $key, + 'start' => $view->start, + 'width' => $view->width, + 'height' => $view->height + ); + + if ($this->view->disabledDatasources) { + $imgParams['disabled'] = $this->view->disabledDatasources; + foreach ($this->view->disabledDatasources as $dis) { + if ($template->hasDatasource($dis)) { + $template->getDatasource($dis)->disable(); + } + } + } + + $this->view->templates[$key] = $template; + + $imgs[$key] = $this->graphiteWeb + ->select() + ->from($template->getFilterString()) + ->where('hostname', $hostname) + ->getWrappedImageLinks($template, $imgParams); + + } + } + + $view->images = $imgs; + } + + public function serviceAction() + { + $this->handleDatasourceToggles(); + $this->handleGraphParams(); + $hostname = $this->view->hostname = $this->params->get('host'); + $service = $this->view->service = $this->params->get('service'); + if (! $hostname) { + throw new NotFoundError('Host is required'); + } + if (! $service) { + throw new NotFoundError('Service is required'); + } + $this->getTabs()->add('service', array( + 'label' => $this->translate('Graphite - Single service'), + 'url' => $this->getRequest()->getUrl() + ))->activate('service'); + + $view = $this->view; + + $imgs = array(); + $this->view->templates = array(); + + foreach ($this->templateStore->loadTemplateSets() as $setname => $set) { + + $patterns = $set->getBasePatterns(); + if (! array_key_exists('icingaHost', $patterns)) continue; + + foreach ($set->loadTemplates() as $key => $template) { + if (strpos($template->getFilterString(), '$service') === false) continue; + + $imgParams = array( + 'template' => $key, + 'start' => $view->start, + 'width' => $view->width, + 'height' => $view->height + ); + + if ($this->view->disabledDatasources) { + $imgParams['disabled'] = $this->view->disabledDatasources; + foreach ($this->view->disabledDatasources as $dis) { + if ($template->hasDatasource($dis)) { + $template->getDatasource($dis)->disable(); + } + + } + } + + $this->view->templates[$key] = $template; + + $imgs[$key] = $this->graphiteWeb + ->select() + ->from($template->getFilterString()) + ->where('hostname', $hostname) + ->where('service', $service) + ->getWrappedImageLinks($template, $imgParams); + + } + } + + $view->images = $imgs; + } + + public function XXXserviceAction() + { + $this->handleDatasourceToggles(); + $this->handleGraphParams(); + $hostname = $this->view->hostname = $this->params->get('host'); + $service = $this->view->service = $this->params->get('service'); + if (! $hostname) { + throw new NotFoundError('Host is required'); + } + if (! $service) { + throw new NotFoundError('Service is required'); + } + $this->getTabs()->add('service', array( + 'label' => $this->translate('Graphite - Single service'), + 'url' => $this->getRequest()->getUrl() + ))->activate('service'); + + $imgs = array(); + $this->view->templates = array(); + + foreach ($this->templateStore->loadTemplateSets() as $setname => $set) { + + $patterns = $set->getBasePatterns(); + if (! array_key_exists('icingaService', $patterns)) continue; + + foreach ($set->loadTemplates() as $key => $template) { + + if (strpos($template->getFilterString(), '$service') === false) continue; + + $this->view->templates[$key] = $template; + + $imgs[$key] = $this->graphiteWeb + ->select() + ->from($template->getFilterString()) + ->where('hostname', $hostname) + ->where('service', $service) + ->getImages($template); + + foreach ($imgs[$key] as $img) { + $this->applyGraphParams($img) + ->showLegend(! $this->params->get('hideLegend', false)); + } } } @@ -248,12 +383,4 @@ class ShowController extends Controller $this->redirectNow($url); } } - - protected function tabs() - { - return $this->view->tabs = Widget::create('tabs')->add('host', array( - 'label' => $this->translate('Graphite - Single Host'), - 'url' => $this->getRequest()->getUrl() - )); - } } diff --git a/run.php b/run.php index db3a6a0..2417d08 100644 --- a/run.php +++ b/run.php @@ -1,4 +1,5 @@ registerHook('Monitoring\\HostActions', '\\Icinga\\Module\\Graphite\\HostActions'); +$this->registerHook('Monitoring\\ServiceActions', '\\Icinga\\Module\\Graphite\\ServiceActions');