diff --git a/library/Icingadb/Hook/Common/TotalSlaReportUtils.php b/library/Icingadb/Hook/Common/TotalSlaReportUtils.php new file mode 100644 index 00000000..d7e7819e --- /dev/null +++ b/library/Icingadb/Hook/Common/TotalSlaReportUtils.php @@ -0,0 +1,56 @@ +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; + } +} diff --git a/library/Icingadb/ProvidedHook/Reporting/TotalHostSlaReport.php b/library/Icingadb/ProvidedHook/Reporting/TotalHostSlaReport.php new file mode 100644 index 00000000..b09ffb75 --- /dev/null +++ b/library/Icingadb/ProvidedHook/Reporting/TotalHostSlaReport.php @@ -0,0 +1,19 @@ +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');