Skip to content

Commit

Permalink
Introduce SLA Chart reports
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Sep 16, 2024
1 parent 334aaf8 commit bd01efc
Show file tree
Hide file tree
Showing 7 changed files with 740 additions and 0 deletions.
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

0 comments on commit bd01efc

Please sign in to comment.