Skip to content

Commit

Permalink
Handle unknown sla results correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Feb 22, 2023
1 parent 807965e commit 6d9f348
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
8 changes: 8 additions & 0 deletions library/Icingadb/ProvidedHook/Reporting/Common/ReportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ public function getAverages()
$problemTime += $timeline->getProblemTime();
}

if ($totalTime <= 0) {
continue;
}

++$count;
$totals += 100 * ($totalTime - $problemTime) / $totalTime;
}

if ($count === 0) {
return [null];
}

return [$totals / $count];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ protected function fetchInitialHardState(DateTime $start, string $hostId, string
$serviceFilter,
Filter::greaterThan('event_time', $start)
)
);
)
->limit(1);

$hardState = $hardState->first();

Expand Down
6 changes: 1 addition & 5 deletions library/Icingadb/ProvidedHook/Reporting/HostSlaReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ protected function createReportData()

protected function createReportRow($row)
{
if ($row->sla === null) {
return null;
}

return (new ReportRow())
->setDimensions([$row->display_name])
->setValues([(float) $row->sla]);
->setValues([$row->sla]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ protected function createReportRow($row)
{
return (new ReportRow())
->setDimensions([$row->host_display_name, $row->display_name])
->setValues([(float) $row->sla]);
->setValues([$row->sla]);
}
}
21 changes: 17 additions & 4 deletions library/Icingadb/ProvidedHook/Reporting/SlaReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,29 @@ public function getHtml(Timerange $timerange, array $config = null)
// We only have one metric
$sla = $row->getValues()[0];

if ($sla < $threshold) {
if ($sla === null) {
$slaClass = 'unknown';
} elseif ($sla < $threshold) {
$slaClass = 'nok';
} else {
$slaClass = 'ok';
}

$cells[] = Html::tag('td', ['class' => "sla-column $slaClass"], round($sla, $precision));
$cells[] = Html::tag(
'td',
['class' => "sla-column $slaClass"],
$sla === null ? t('N/A') : round($sla, $precision)
);

$tableRows[] = Html::tag('tr', null, $cells);
}

// We only have one average
$average = $data->getAverages()[0];
if ($average < $threshold) {

if ($average === null) {
$slaClass = 'unknown';
} elseif ($average < $threshold) {
$slaClass = 'nok';
} else {
$slaClass = 'ok';
Expand All @@ -144,7 +153,11 @@ public function getHtml(Timerange $timerange, array $config = null)

$tableRows[] = Html::tag('tr', null, [
Html::tag('td', ['colspan' => count($data->getDimensions())], $total),
Html::tag('td', ['class' => "sla-column $slaClass"], round($average, $precision))
Html::tag(
'td',
['class' => "sla-column $slaClass"],
$average === null ? t('N/A') : round($average, $precision)
)
]);

$table = Html::tag(
Expand Down

0 comments on commit 6d9f348

Please sign in to comment.