blob: d9c4f4f13e6937485732e945b5582008bac2c7c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
/* Icinga DB Web | (c) 2022 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\ProvidedHook\Reporting;
use Icinga\Application\Icinga;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Reporting\ReportData;
use Icinga\Module\Reporting\ReportRow;
use Icinga\Module\Reporting\Timerange;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter\Rule;
use function ipl\I18n\t;
class HostSlaReport extends SlaReport
{
public function getName()
{
$name = t('Host SLA');
if (Icinga::app()->getModuleManager()->hasEnabled('idoreports')) {
$name .= ' (Icinga DB)';
}
return $name;
}
protected function createReportData()
{
return (new ReportData())
->setDimensions([t('Hostname')])
->setValues([t('SLA in %')]);
}
protected function createReportRow($row)
{
if ($row->sla === null) {
return null;
}
return (new ReportRow())
->setDimensions([$row->display_name])
->setValues([(float) $row->sla]);
}
protected function fetchSla(Timerange $timerange, Rule $filter = null)
{
$sla = Host::on($this->getDb())
->columns([
'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;
}
}
|