Skip to content

Commit

Permalink
Merge pull request #288 from raviks789/feature/icingadb-support
Browse files Browse the repository at this point in the history
Add icingadb support for grafana module
  • Loading branch information
Mikesch-mp committed Feb 23, 2023
2 parents 7e27158 + 2e7a98a commit 7a86b88
Show file tree
Hide file tree
Showing 15 changed files with 1,577 additions and 1 deletion.
7 changes: 7 additions & 0 deletions application/controllers/DashboardController.php
Expand Up @@ -2,10 +2,13 @@

namespace Icinga\Module\Grafana\Controllers;

use Icinga\Application\Modules\Module;
use Icinga\Module\Grafana\ProvidedHook\Grapher;
use Icinga\Module\Grafana\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Object\Service;
use ipl\Web\Url;

class DashboardController extends Controller
{
Expand All @@ -17,6 +20,10 @@ public function init()

public function indexAction()
{
if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) {
$this->redirectNow(Url::fromPath('grafana/icingadbdashboard')->setQueryString($this->params));
}

$this->getTabs()->add('graphs', array(
'active' => true,
'label' => $this->translate('Graphs'),
Expand Down
72 changes: 72 additions & 0 deletions application/controllers/IcingadbdashboardController.php
@@ -0,0 +1,72 @@
<?php

namespace Icinga\Module\Grafana\Controllers;

use Icinga\Exception\NotFoundError;
use Icinga\Module\Grafana\ProvidedHook\Icingadb\HostDetailExtension;
use Icinga\Module\Grafana\ProvidedHook\Icingadb\ServiceDetailExtension;
use Icinga\Module\Grafana\Web\Controller\IcingadbGrafanaController;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
use ipl\Stdlib\Filter;
use ipl\Web\Url;

class IcingadbdashboardController extends IcingadbGrafanaController
{
public function init()
{
$this->assertPermission('grafana/graph');
$this->setAutorefreshInterval(15);
}

public function indexAction()
{
if (! $this->useIcingadbAsBackend) {
$this->redirectNow(Url::fromPath('grafana/dashboard')->setQueryString($this->params));
}

$this->getTabs()->add(
'graphs',
[
'active' => true,
'label' => $this->translate('Graphs'),
'url' => $this->getRequest()->getUrl()
]
);

$hostName = $this->params->getRequired('host');
$serviceName = $this->params->get('service');

if ($serviceName != null) {
$query = Service::on($this->getDb())->with([
'state',
'icon_image',
'host',
'host.state'
]);
$query->filter(
Filter::all(
Filter::equal('service.name', $serviceName),
Filter::equal('host.name', $hostName)
)
);
} else {
$query = Host::on($this->getDb())->with(['state', 'icon_image']);
$query->filter(Filter::equal('host.name', $hostName));
}

$this->applyRestrictions($query);
$object = $query->first();
if ($object === null) {
throw new NotFoundError(t('Host or Service not found'));
}

if ($object instanceof Host) {
$graph = new HostDetailExtension();
} else {
$graph = new ServiceDetailExtension();
}

$this->addContent($graph->getPreviewHtml($object));
}
}

0 comments on commit 7a86b88

Please sign in to comment.