From ad74a640833261e82f49d2c8fc13ed03428bf5e0 Mon Sep 17 00:00:00 2001 From: Christoph Breit Date: Tue, 21 Apr 2026 11:34:14 +0200 Subject: [PATCH 1/3] remove graphs controller and move it to a seperate tab --- application/controllers/GraphsController.php | 124 ------------------ doc/10-Dashboard.md | 12 +- .../Icingadb/HostDetailExtension.php | 13 -- .../Icingadb/ServiceDetailExtension.php | 13 -- .../ProvidedHook/Icingadb/Tab.php | 107 +++++++++++++++ .../Monitoring/DetailviewExtension.php | 13 -- .../Monitoring/ObjectDetailsTab.php | 106 +++++++++++++++ run.php | 2 + 8 files changed, 221 insertions(+), 169 deletions(-) delete mode 100644 application/controllers/GraphsController.php create mode 100644 library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php create mode 100644 library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php diff --git a/application/controllers/GraphsController.php b/application/controllers/GraphsController.php deleted file mode 100644 index c9828e6..0000000 --- a/application/controllers/GraphsController.php +++ /dev/null @@ -1,124 +0,0 @@ -add(HtmlElement::create('p', ['class' => 'line-chart-error preformatted'], $message)); - $this->addContent($err); - } - - /** - * Initialize the Controller. - */ - public function init(): void - { - // Assert the user has access to this controller. - $this->assertPermission('perfdatagraphs/view'); - parent::init(); - } - - public function indexAction(): void - { - $this->getTabs() - ->add('graph', [ - 'label' => 'Graph', - 'url' => 'perfdatagraphs/graph' - ]) - ->activate('graph'); - - // Load the module's configuration. - $config = ModuleConfig::getConfigWithDefaults(); - $defaultDuration = $config['default_timerange']; - $duration = $this->params->get('perfdatagraphs.duration', $defaultDuration); - $headline = $this->params->get('perfdatagraphs.headline', $this->translate('Performance Data Graph')); - - // Retrieve the URL parameters. - $hostName = $this->params->getRequired('host'); - $serviceName = $this->params->getRequired('service'); - $checkcommandName = $this->params->getRequired('checkcommand'); - $isHostCheck = $this->params->getRequired('ishostcheck'); - - // Optional list of labels, when passed only the given perfdata metrics will be shown - $labels = $this->params->getValues('label'); - - // Transform the URL param into a boolean just because it is easier to work with - $isHostCheck = $isHostCheck === 'true' ? true : false; - - $header = Html::tag('h2', $headline); - $this->addContent($header); - - if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { - Logger::debug('Used IcingaDB as database backend'); - $cvh = new IcinaDBCVH(); - } else { - Logger::debug('Used IDO as database backend'); - $cvh = new IdoCVH(); - } - - // Get the object so that we can get its custom variables. - $object = $cvh->getObjectFromString($hostName, $serviceName, $isHostCheck); - - if (empty($object)) { - $this->addError($this->translate('Failed to find object from given host-service strings')); - return; - } - - $customvars = $cvh->getPerfdataGraphsConfigForObject($object); - - // If the object wants the data from a custom backend - if ($customvars[$cvh::CUSTOM_VAR_CONFIG_BACKEND] ?? false) { - $hook = ModuleConfig::getHookByName($customvars[$cvh::CUSTOM_VAR_CONFIG_BACKEND]); - } else { - $hook = ModuleConfig::getHook(); - } - // If there is no hook configured we return here. - if (empty($hook)) { - $this->addError($this->translate('No hook configured')); - return; - } - - $source = new PerfdataSource($config, $hook); - $request = new PerfdataRequest($hostName, $serviceName, $checkcommandName, $duration, $isHostCheck, [], []); - - $customVarsMetrics = $cvh->getPerfdataGraphsMetricsForObject($object); - - $response = $source->fetch($request, $customVarsMetrics); - - $limit = -1; - $chart = $this->createChart(request: $request, response: $response, filter: $labels, limit: $limit); - - if (empty($chart)) { - $this->addError($this->translate('Chart could not be renderd')); - return; - } - - $this->addContent(HtmlString::create($chart)); - } -} diff --git a/doc/10-Dashboard.md b/doc/10-Dashboard.md index 030d23e..cfb1b92 100644 --- a/doc/10-Dashboard.md +++ b/doc/10-Dashboard.md @@ -2,7 +2,9 @@ The module offers a dedicated page for graphs that can be used on an Icinga Web Dashboard. -This page is available at `perfdatagraphs/graphs`. +This page is available at `icingadb/host/graphs?name=yourHostName` for Hosts and at `icingadb/service/graphs?name=yourServiceName&host.name=yourHostName` for Service +or `monitoring/host/tabhook?host=yourHostName&hook=graphs` or `monitoring/service/tabhook?host=yourHostName&service=yourServiceName&hook=graphs` depending if you use the icingadb or monitoring module. + HTTP parameters are used to managed what is rendered: @@ -19,12 +21,10 @@ HTTP parameters are used to managed what is rendered: Example: +IcingaDB Host ``` -http://icingaweb2.internal/perfdatagraphs/graphs - ?host=example - &service=http - &checkcommand=http - &ishostcheck=false +http://icingaweb2.internal/icingadb/host/graphs + ?name=example &perfdatagraphs.duration=P1D &perfdatagraphs.headline=Example Host HTTP Service &label=time&label=size diff --git a/library/Perfdatagraphs/ProvidedHook/Icingadb/HostDetailExtension.php b/library/Perfdatagraphs/ProvidedHook/Icingadb/HostDetailExtension.php index c3c8ba4..3c9e581 100644 --- a/library/Perfdatagraphs/ProvidedHook/Icingadb/HostDetailExtension.php +++ b/library/Perfdatagraphs/ProvidedHook/Icingadb/HostDetailExtension.php @@ -15,7 +15,6 @@ use ipl\Html\HtmlElement; use ipl\Html\ValidHtml; use ipl\Web\Url; -use ipl\Web\Widget\Link; /** * HostDetailExtension adds the Chart HTML for Host objects. @@ -99,21 +98,9 @@ public function getHtmlForObject(Host $host): ValidHtml $headline = $this->translate('Performance Data Graph'); $header = Html::tag('h2', $headline); - $link = new Link( - $this->translate('Show all performance data graphs'), - Url::fromPath('perfdatagraphs/graphs')->addParams([ - 'host' => $hostName, - 'service' => $serviceName, - 'checkcommand' => $checkCommandName, - 'ishostcheck' => 'true', - 'perfdatagraphs.headline' => $headline - ]), - ); - $d = Html::tag('div'); $d->add($header); $d->add($chart); - $d->add($link); return $d; } diff --git a/library/Perfdatagraphs/ProvidedHook/Icingadb/ServiceDetailExtension.php b/library/Perfdatagraphs/ProvidedHook/Icingadb/ServiceDetailExtension.php index 59528dd..a15b184 100644 --- a/library/Perfdatagraphs/ProvidedHook/Icingadb/ServiceDetailExtension.php +++ b/library/Perfdatagraphs/ProvidedHook/Icingadb/ServiceDetailExtension.php @@ -15,7 +15,6 @@ use ipl\Html\HtmlElement; use ipl\Html\ValidHtml; use ipl\Web\Url; -use ipl\Web\Widget\Link; /** * ServiceDetailExtension adds the Chart HTML for Service objects. @@ -99,21 +98,9 @@ public function getHtmlForObject(Service $service): ValidHtml $headline = $this->translate('Performance Data Graph'); $header = Html::tag('h2', $headline); - $link = new Link( - $this->translate('Show all performance data graphs'), - Url::fromPath('perfdatagraphs/graphs')->addParams([ - 'host' => $hostName, - 'service' => $serviceName, - 'checkcommand' => $checkCommandName, - 'ishostcheck' => 'false', - 'perfdatagraphs.headline' => $headline - ]), - ); - $d = Html::tag('div'); $d->add($header); $d->add($chart); - $d->add($link); return $d; } diff --git a/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php b/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php new file mode 100644 index 0000000..7d5e487 --- /dev/null +++ b/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php @@ -0,0 +1,107 @@ +add(HtmlElement::create('p', ['class' => 'line-chart-error preformatted'], $message)); + return $err; + } + + public function getContent(Model $object): array + { + $isHostCheck = false; + if ($object instanceof Host) { + $serviceName = $object->checkcommand_name; + $isHostCheck = true; + $checkcommandName = $object->checkcommand_name; + $hostName = $object->name; + } elseif ($object instanceof Service) { + $serviceName = $object->name; + $checkcommandName = $object->checkcommand_name; + $hostName = $object->host->name; + } + $request = Icinga::app()->getRequest(); + + $content = []; + $config = ModuleConfig::getConfigWithDefaults(); + $defaultDuration = $config['default_timerange']; + + // Retrieve the URL parameters. + $duration = $request->getParam('perfdatagraphs_duration', $defaultDuration); + $headline = $request->getParam('perfdatagraphs_headline', $this->translate('Performance Data Graph')); + + // Optional list of labels, when passed only the given perfdata metrics will be shown + $labels = $request->getParam('labels', []); + + $header = Html::tag('h2', $headline); + $content[] = $header; + + if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { + Logger::debug('Used IcingaDB as database backend'); + $cvh = new IcingaObjectHelper(); + } + + $customvars = $cvh->getPerfdataGraphsConfigForObject($object); + + // If the object wants the data from a custom backend + if ($customvars[$cvh::CUSTOM_VAR_CONFIG_BACKEND] ?? false) { + $hook = ModuleConfig::getHookByName($customvars[$cvh::CUSTOM_VAR_CONFIG_BACKEND]); + } else { + $hook = ModuleConfig::getHook(); + } + // If there is no hook configured we return here. + if (empty($hook)) { + $content[] = $this->addError($this->translate('No hook configured')); + return $content; + } + + $source = new PerfdataSource($config, $hook); + $request = new PerfdataRequest($hostName, $serviceName, $checkcommandName, $duration, $isHostCheck, [], []); + + $customVarsMetrics = $cvh->getPerfdataGraphsMetricsForObject($object); + + $response = $source->fetch($request, $customVarsMetrics); + + $limit = -1; + $chart = $this->createChart(request: $request, response: $response, filter: $labels, limit: $limit); + $content[] = HtmlString::create($chart); + + if (empty($chart)) { + $content[] = $this->addError($this->translate('Chart could not be rendered')); + return $content; + } + return $content; + } +} diff --git a/library/Perfdatagraphs/ProvidedHook/Monitoring/DetailviewExtension.php b/library/Perfdatagraphs/ProvidedHook/Monitoring/DetailviewExtension.php index 755b964..4ce10a4 100644 --- a/library/Perfdatagraphs/ProvidedHook/Monitoring/DetailviewExtension.php +++ b/library/Perfdatagraphs/ProvidedHook/Monitoring/DetailviewExtension.php @@ -16,7 +16,6 @@ use ipl\Html\Html; use ipl\Html\HtmlElement; use ipl\Web\Url; -use ipl\Web\Widget\Link; class DetailviewExtension extends DetailviewExtensionHook { @@ -106,21 +105,9 @@ public function getHtmlForObject(MonitoredObject $object) $headline = $this->translate('Performance Data Graph'); $header = Html::tag('h2', $headline); - $link = new Link( - $this->translate('Show all performance data graphs'), - Url::fromPath('perfdatagraphs/graphs')->addParams([ - 'host' => $hostName, - 'service' => $serviceName, - 'checkcommand' => $checkCommandName, - 'ishostcheck' => $isHostCheck, - 'perfdatagraphs.headline' => $headline - ]), - ); - $d = Html::tag('div'); $d->add($header); $d->add($chart); - $d->add($link); return $d; } diff --git a/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php b/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php new file mode 100644 index 0000000..1effb2c --- /dev/null +++ b/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php @@ -0,0 +1,106 @@ +add(HtmlElement::create('p', ['class' => 'line-chart-error preformatted'], $message)); + return $err; + } + + + public function getContent(MonitoredObject $object, Request $request) + { + $isHostCheck = false; + + if ($object instanceof Host) { + $serviceName = $object->host_check_command; + $hostName = $object->getName(); + $checkCommandName = $object->host_check_command; + $isHostCheck = true; + } elseif ($object instanceof Service) { + $serviceName = $object->getName(); + $hostName = $object->getHost()->getName(); + $checkCommandName = $object->check_command; + } else { + return Html::tag('div'); + } + + $content = ""; + $config = ModuleConfig::getConfigWithDefaults(); + $defaultDuration = $config['default_timerange']; + // Retrieve the URL parameters. + $duration = $request->getParam('perfdatagraphs_duration', $defaultDuration); + $headline = $request->getParam('perfdatagraphs_headline', $this->translate('Performance Data Graph')); + + // Optional list of labels, when passed only the given perfdata metrics will be shown + $labels = $request->getParam('labels', []); + + $header = Html::tag('h2', $headline); + $content = $content . $header; + + Logger::debug('Used IDO as database backend'); + $cvh = new IdoCVH(); + + $customvars = $cvh->getPerfdataGraphsConfigForObject($object); + + // If the object wants the data from a custom backend + if ($customvars[$cvh::CUSTOM_VAR_CONFIG_BACKEND] ?? false) { + $hook = ModuleConfig::getHookByName($customvars[$cvh::CUSTOM_VAR_CONFIG_BACKEND]); + } else { + $hook = ModuleConfig::getHook(); + } + // If there is no hook configured we return here. + if (empty($hook)) { + return $this->addError($this->translate('No hook configured')); + } + + $source = new PerfdataSource($config, $hook); + $newRequest = new PerfdataRequest($hostName, $serviceName, $checkCommandName, $duration, $isHostCheck, [], []); + + $customVarsMetrics = $cvh->getPerfdataGraphsMetricsForObject($object); + + $response = $source->fetch($newRequest, $customVarsMetrics); + + $limit = -1; + $chart = $this->createChart(request: $newRequest, response: $response, filter: $labels, limit: $limit); + $content = $content . $chart; + + if (empty($chart)) { + return $this->addError($this->translate('Chart could not be rendered')); + } + return Html::tag('div', ['class' => 'icinga-module module-perfdatagraphs'], HtmlString::create($content)); + } +} diff --git a/run.php b/run.php index 3455c0c..bb94cf4 100644 --- a/run.php +++ b/run.php @@ -5,4 +5,6 @@ $this->provideHook('icingadb/IcingadbSupport'); $this->provideHook('icingadb/ServiceDetailExtension'); $this->provideHook('icingadb/HostDetailExtension'); +$this->provideHook('icingadb/Tab'); +$this->provideHook('monitoring/ObjectDetailsTab'); $this->provideHook('monitoring/DetailviewExtension'); From 43eb486abd1a265891dfe9e43440cd22a1a7b053 Mon Sep 17 00:00:00 2001 From: Christoph Breit Date: Tue, 21 Apr 2026 15:21:35 +0200 Subject: [PATCH 2/3] remove headline and rename tab --- library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php | 6 +----- .../ProvidedHook/Monitoring/ObjectDetailsTab.php | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php b/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php index 7d5e487..d0c8933 100644 --- a/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php +++ b/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php @@ -29,7 +29,7 @@ public function getName(): string public function getLabel(): string { - return t('All graphs'); + return t('Performance Data Graph'); } protected function addError(string $message): HtmlElement @@ -60,14 +60,10 @@ public function getContent(Model $object): array // Retrieve the URL parameters. $duration = $request->getParam('perfdatagraphs_duration', $defaultDuration); - $headline = $request->getParam('perfdatagraphs_headline', $this->translate('Performance Data Graph')); // Optional list of labels, when passed only the given perfdata metrics will be shown $labels = $request->getParam('labels', []); - $header = Html::tag('h2', $headline); - $content[] = $header; - if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { Logger::debug('Used IcingaDB as database backend'); $cvh = new IcingaObjectHelper(); diff --git a/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php b/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php index 1effb2c..4232333 100644 --- a/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php +++ b/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php @@ -30,7 +30,7 @@ public function getName() public function getLabel() { - return "All graphs"; + return "Performance Data Graph"; } protected function addError(string $message): HtmlElement @@ -63,14 +63,10 @@ public function getContent(MonitoredObject $object, Request $request) $defaultDuration = $config['default_timerange']; // Retrieve the URL parameters. $duration = $request->getParam('perfdatagraphs_duration', $defaultDuration); - $headline = $request->getParam('perfdatagraphs_headline', $this->translate('Performance Data Graph')); // Optional list of labels, when passed only the given perfdata metrics will be shown $labels = $request->getParam('labels', []); - $header = Html::tag('h2', $headline); - $content = $content . $header; - Logger::debug('Used IDO as database backend'); $cvh = new IdoCVH(); From 972260a94df94eb0a6ddb751633785bcda8c1f2c Mon Sep 17 00:00:00 2001 From: Christoph Breit Date: Wed, 22 Apr 2026 09:10:38 +0200 Subject: [PATCH 3/3] code cleanup and documentation update --- doc/10-Dashboard.md | 16 ++++++------ .../ProvidedHook/Icingadb/Tab.php | 25 +++++++++--------- .../Monitoring/ObjectDetailsTab.php | 26 +++++++++---------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/doc/10-Dashboard.md b/doc/10-Dashboard.md index cfb1b92..d586bbb 100644 --- a/doc/10-Dashboard.md +++ b/doc/10-Dashboard.md @@ -2,9 +2,15 @@ The module offers a dedicated page for graphs that can be used on an Icinga Web Dashboard. -This page is available at `icingadb/host/graphs?name=yourHostName` for Hosts and at `icingadb/service/graphs?name=yourServiceName&host.name=yourHostName` for Service -or `monitoring/host/tabhook?host=yourHostName&hook=graphs` or `monitoring/service/tabhook?host=yourHostName&service=yourServiceName&hook=graphs` depending if you use the icingadb or monitoring module. +With the IcingaDB module at: +* `icingadb/host/graphs?name=yourHostName` +* `icingadb/service/graphs?name=yourServiceName&host.name=yourHostName` + +With the Monitoring module at: + +* `monitoring/host/tabhook?host=yourHostName&hook=graphs` +* `monitoring/service/tabhook?host=yourHostName&service=yourServiceName&hook=graphs` HTTP parameters are used to managed what is rendered: @@ -12,20 +18,14 @@ HTTP parameters are used to managed what is rendered: |---------|--------| | `host` | Name of the Icinga host | | `service` | Name of the Icinga service | -| `checkcommand` | Name of the Icinga check command | -| `ishostcheck` | is this a Host or Service Check that is requested | -| `perfdatagraphs.duration` | duration for which to fetch the data for in PHP's [DateInterval](https://www.php.net/manual/en/class.dateinterval.php) format (e.g. PT12H, P1D, P1Y) | | `label` | (optional) Name of a specific performance data label to render. Can be used multiple times | | `perfdatagraphs.duration` | duration for which to fetch the data for in PHP's [DateInterval](https://www.php.net/manual/en/class.dateinterval.php) format (e.g. PT12H, P1D, P1Y) | -| `perfdatagraphs.headline` | Headline for the page. | Example: -IcingaDB Host ``` http://icingaweb2.internal/icingadb/host/graphs ?name=example &perfdatagraphs.duration=P1D - &perfdatagraphs.headline=Example Host HTTP Service &label=time&label=size ``` diff --git a/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php b/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php index d0c8933..2e60d27 100644 --- a/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php +++ b/library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php @@ -2,17 +2,18 @@ namespace Icinga\Module\Perfdatagraphs\ProvidedHook\Icingadb; -use Icinga\Application\Icinga; -use Icinga\Application\Logger; -use Icinga\Application\Modules\Module; -use Icinga\Module\Icingadb\Hook\TabHook; -use Icinga\Module\Icingadb\Model\Host; -use Icinga\Module\Icingadb\Model\Service; use Icinga\Module\Perfdatagraphs\Common\ModuleConfig; use Icinga\Module\Perfdatagraphs\Common\PerfdataChart; use Icinga\Module\Perfdatagraphs\Common\PerfdataSource; use Icinga\Module\Perfdatagraphs\Icingadb\IcingaObjectHelper; use Icinga\Module\Perfdatagraphs\Model\PerfdataRequest; + +use Icinga\Module\Icingadb\Hook\TabHook; +use Icinga\Module\Icingadb\Model\Host; +use Icinga\Module\Icingadb\Model\Service; + +use Icinga\Application\Icinga; + use ipl\Html\Html; use ipl\Html\HtmlElement; use ipl\Html\HtmlString; @@ -20,8 +21,8 @@ class Tab extends TabHook { - use PerfdataChart; + public function getName(): string { return 'graphs'; @@ -52,9 +53,9 @@ public function getContent(Model $object): array $checkcommandName = $object->checkcommand_name; $hostName = $object->host->name; } + $request = Icinga::app()->getRequest(); - $content = []; $config = ModuleConfig::getConfigWithDefaults(); $defaultDuration = $config['default_timerange']; @@ -64,10 +65,7 @@ public function getContent(Model $object): array // Optional list of labels, when passed only the given perfdata metrics will be shown $labels = $request->getParam('labels', []); - if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { - Logger::debug('Used IcingaDB as database backend'); - $cvh = new IcingaObjectHelper(); - } + $cvh = new IcingaObjectHelper(); $customvars = $cvh->getPerfdataGraphsConfigForObject($object); @@ -77,7 +75,9 @@ public function getContent(Model $object): array } else { $hook = ModuleConfig::getHook(); } + // If there is no hook configured we return here. + $content = []; if (empty($hook)) { $content[] = $this->addError($this->translate('No hook configured')); return $content; @@ -98,6 +98,7 @@ public function getContent(Model $object): array $content[] = $this->addError($this->translate('Chart could not be rendered')); return $content; } + return $content; } } diff --git a/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php b/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php index 4232333..5455cc4 100644 --- a/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php +++ b/library/Perfdatagraphs/ProvidedHook/Monitoring/ObjectDetailsTab.php @@ -2,27 +2,27 @@ namespace Icinga\Module\PerfdataGraphs\ProvidedHook\Monitoring; -use Icinga\Application\Logger; -use Icinga\Application\Modules\Module; -use Icinga\Module\Monitoring\Object\Host; -use Icinga\Module\Monitoring\Object\Service; use Icinga\Module\Perfdatagraphs\Common\ModuleConfig; use Icinga\Module\Perfdatagraphs\Common\PerfdataChart; use Icinga\Module\Perfdatagraphs\Common\PerfdataSource; use Icinga\Module\Perfdatagraphs\Ido\IcingaObjectHelper as IdoCVH; -use Icinga\Module\Perfdatagraphs\Icingadb\IcingaObjectHelper as IcinaDBCVH; use Icinga\Module\Perfdatagraphs\Model\PerfdataRequest; -use Icinga\Module\Perfdatagraphs\ProvidedHook\Icingadb\IcingadbSupport; + +use Icinga\Module\Monitoring\Hook\ObjectDetailsTabHook; +use Icinga\Module\Monitoring\Object\Host; +use Icinga\Module\Monitoring\Object\MonitoredObject; +use Icinga\Module\Monitoring\Object\Service; + +use Icinga\Web\Request; + use ipl\Html\Html; use ipl\Html\HtmlElement; use ipl\Html\HtmlString; -use Icinga\Module\Monitoring\Object\MonitoredObject; -use Icinga\Web\Request; -use Icinga\Module\Monitoring\Hook\ObjectDetailsTabHook; class ObjectDetailsTab extends ObjectDetailsTabHook { use PerfdataChart; + public function getName() { return "graphs"; @@ -40,7 +40,6 @@ protected function addError(string $message): HtmlElement return $err; } - public function getContent(MonitoredObject $object, Request $request) { $isHostCheck = false; @@ -58,7 +57,6 @@ public function getContent(MonitoredObject $object, Request $request) return Html::tag('div'); } - $content = ""; $config = ModuleConfig::getConfigWithDefaults(); $defaultDuration = $config['default_timerange']; // Retrieve the URL parameters. @@ -67,7 +65,6 @@ public function getContent(MonitoredObject $object, Request $request) // Optional list of labels, when passed only the given perfdata metrics will be shown $labels = $request->getParam('labels', []); - Logger::debug('Used IDO as database backend'); $cvh = new IdoCVH(); $customvars = $cvh->getPerfdataGraphsConfigForObject($object); @@ -78,6 +75,7 @@ public function getContent(MonitoredObject $object, Request $request) } else { $hook = ModuleConfig::getHook(); } + // If there is no hook configured we return here. if (empty($hook)) { return $this->addError($this->translate('No hook configured')); @@ -92,11 +90,11 @@ public function getContent(MonitoredObject $object, Request $request) $limit = -1; $chart = $this->createChart(request: $newRequest, response: $response, filter: $labels, limit: $limit); - $content = $content . $chart; if (empty($chart)) { return $this->addError($this->translate('Chart could not be rendered')); } - return Html::tag('div', ['class' => 'icinga-module module-perfdatagraphs'], HtmlString::create($content)); + + return Html::tag('div', ['class' => 'icinga-module module-perfdatagraphs'], HtmlString::create($chart)); } }