Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 0 additions & 124 deletions application/controllers/GraphsController.php

This file was deleted.

22 changes: 11 additions & 11 deletions doc/10-Dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

The module offers a dedicated page for graphs that can be used on an Icinga Web Dashboard.

This page is available at `perfdatagraphs/graphs`.
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:

| Parameter | Function |
|---------|--------|
| `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:

```
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
```
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
104 changes: 104 additions & 0 deletions library/Perfdatagraphs/ProvidedHook/Icingadb/Tab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Icinga\Module\Perfdatagraphs\ProvidedHook\Icingadb;

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;
use ipl\Orm\Model;

class Tab extends TabHook
{
use PerfdataChart;

public function getName(): string
{
return 'graphs';
}

public function getLabel(): string
{
return t('Performance Data Graph');
}

protected function addError(string $message): HtmlElement
{
$err = Html::tag('div');
$err->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();

$config = ModuleConfig::getConfigWithDefaults();
$defaultDuration = $config['default_timerange'];

// Retrieve the URL parameters.
$duration = $request->getParam('perfdatagraphs_duration', $defaultDuration);

// Optional list of labels, when passed only the given perfdata metrics will be shown
$labels = $request->getParam('labels', []);

$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.
$content = [];
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down
Loading