mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Introduce Total Host and Total Service SLA Report
This commit is contained in:
parent
ec71e3640d
commit
cf068f390f
4 changed files with 96 additions and 0 deletions
56
library/Icingadb/Hook/Common/TotalSlaReportUtils.php
Normal file
56
library/Icingadb/Hook/Common/TotalSlaReportUtils.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */
|
||||
|
||||
namespace Icinga\Module\Icingadb\Hook\Common;
|
||||
|
||||
use Icinga\Module\Icingadb\ProvidedHook\Reporting\HostSlaReport;
|
||||
use Icinga\Module\Icingadb\Widget\EmptyState;
|
||||
use Icinga\Module\Reporting\Timerange;
|
||||
use ipl\Html\Html;
|
||||
|
||||
use function ipl\I18n\t;
|
||||
|
||||
trait TotalSlaReportUtils
|
||||
{
|
||||
public function getHtml(Timerange $timerange, array $config = null)
|
||||
{
|
||||
$data = $this->getData($timerange, $config);
|
||||
$count = $data->count();
|
||||
|
||||
if (! $count) {
|
||||
return new EmptyState(t('No data found.'));
|
||||
}
|
||||
|
||||
$threshold = (float) ($config['threshold'] ?? static::DEFAULT_THRESHOLD);
|
||||
|
||||
$tableRows = [];
|
||||
$precision = $config['sla_precision'] ?? static::DEFAULT_REPORT_PRECISION;
|
||||
|
||||
// We only have one average
|
||||
$average = $data->getAverages()[0];
|
||||
|
||||
if ($average < $threshold) {
|
||||
$slaClass = 'nok';
|
||||
} else {
|
||||
$slaClass = 'ok';
|
||||
}
|
||||
|
||||
$total = $this instanceof HostSlaReport
|
||||
? sprintf(t('Total (%d Hosts)'), $count)
|
||||
: sprintf(t('Total (%d Services)'), $count);
|
||||
|
||||
$tableRows[] = Html::tag('tr', null, [
|
||||
Html::tag('td', ['colspan' => count($data->getDimensions())], $total),
|
||||
Html::tag('td', ['class' => "sla-column $slaClass"], round($average, $precision))
|
||||
]);
|
||||
|
||||
$table = Html::tag(
|
||||
'table',
|
||||
['class' => 'common-table sla-table'],
|
||||
[Html::tag('tbody', null, $tableRows)]
|
||||
);
|
||||
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */
|
||||
|
||||
namespace Icinga\Module\Icingadb\ProvidedHook\Reporting;
|
||||
|
||||
use Icinga\Module\Icingadb\Hook\Common\TotalSlaReportUtils;
|
||||
|
||||
use function ipl\I18n\t;
|
||||
|
||||
class TotalHostSlaReport extends HostSlaReport
|
||||
{
|
||||
use TotalSlaReportUtils;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return t('Total Host SLA');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */
|
||||
|
||||
namespace Icinga\Module\Icingadb\ProvidedHook\Reporting;
|
||||
|
||||
use Icinga\Module\Icingadb\Hook\Common\TotalSlaReportUtils;
|
||||
|
||||
use function ipl\I18n\t;
|
||||
|
||||
class TotalServiceSlaReport extends ServiceSlaReport
|
||||
{
|
||||
use TotalSlaReportUtils;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return t('Total Service SLA');
|
||||
}
|
||||
}
|
||||
2
run.php
2
run.php
|
|
@ -9,7 +9,9 @@ $this->provideHook('X509/Sni');
|
|||
$this->provideHook('health', 'IcingaHealth');
|
||||
$this->provideHook('health', 'RedisHealth');
|
||||
$this->provideHook('Reporting/Report', 'Reporting/HostSlaReport');
|
||||
$this->provideHook('Reporting/Report', 'Reporting/TotalHostSlaReport');
|
||||
$this->provideHook('Reporting/Report', 'Reporting/ServiceSlaReport');
|
||||
$this->provideHook('Reporting/Report', 'Reporting/TotalServiceSlaReport');
|
||||
|
||||
if ($this::exists('reporting')) {
|
||||
$this->provideHook('Icingadb/HostsDetailExtension', 'CreateHostSlaReport');
|
||||
|
|
|
|||
Loading…
Reference in a new issue