Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SLA Chart reports #1051

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,5 @@
$this->provideJsFile('loadmore.js');
$this->provideJsFile('migrate.js');
$this->provideJsFile('progress-bar.js');
$this->provideJsFile('billboard.js');
}
49 changes: 49 additions & 0 deletions library/Icingadb/ProvidedHook/Reporting/HostSlaChartReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\ProvidedHook\Reporting;

use Icinga\Application\Icinga;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Reporting\Timerange;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter\Rule;

use function ipl\I18n\t;

class HostSlaChartReport extends SlaChartReport
{
public function getName()
{
$name = t('Host SLA Chart');
if (Icinga::app()->getModuleManager()->hasEnabled('idoreports')) {
$name .= ' (Icinga DB)';
}

return $name;
}

protected function fetchSla(Timerange $timerange, Rule $filter = null)
{
$sla = Host::on($this->getDb())
->columns([
'id',
'display_name',
'sla' => new Expression(sprintf(
"get_sla_ok_percent(%s, NULL, '%s', '%s')",
'host.id',
$timerange->getStart()->format('Uv'),
$timerange->getEnd()->format('Uv')
)),
]);

$this->applyRestrictions($sla);

if ($filter !== null) {
$sla->filter($filter);
}

return $sla;
}
}
53 changes: 53 additions & 0 deletions library/Icingadb/ProvidedHook/Reporting/ServiceSlaChartReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\ProvidedHook\Reporting;

use Icinga\Application\Icinga;
use Icinga\Module\Icingadb\Model\Service;
use Icinga\Module\Reporting\Timerange;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter\Rule;

use function ipl\I18n\t;

class ServiceSlaChartReport extends SlaChartReport
{
public function getName()
{
$name = t('Service SLA Chart');
if (Icinga::app()->getModuleManager()->hasEnabled('idoreports')) {
$name .= ' (Icinga DB)';
}

return $name;
}

protected function fetchSla(Timerange $timerange, Rule $filter = null)
{
$sla = Service::on($this->getDb())
->columns([
'id',
'host.display_name',
'display_name',
'sla' => new Expression(sprintf(
"get_sla_ok_percent(%s, %s, '%s', '%s')",
'service.host_id',
'service.id',
$timerange->getStart()->format('Uv'),
$timerange->getEnd()->format('Uv')
))
]);

$sla->resetOrderBy()->orderBy('host.display_name')->orderBy('display_name');

$this->applyRestrictions($sla);

if ($filter !== null) {
$sla->filter($filter);
}

return $sla;
}
}
Loading
Loading