Skip to content

Commit 881dbf2

Browse files
committed
Handle unknown sla results correctly
1 parent 9b1d1b5 commit 881dbf2

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

library/Icingadb/ProvidedHook/Reporting/Common/ReportData.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ public function getAverages()
2424
$problemTime += $timeline->getProblemTime();
2525
}
2626

27+
if ($totalTime <= 0) {
28+
continue;
29+
}
30+
2731
++$count;
2832
$totals += 100 * ($totalTime - $problemTime) / $totalTime;
2933
}
3034

35+
if ($count === 0) {
36+
return [null];
37+
}
38+
3139
return [$totals / $count];
3240
}
3341
}

library/Icingadb/ProvidedHook/Reporting/Common/SlaReportUtils.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ protected function fetchInitialHardState(DateTime $start, string $hostId, string
325325
$serviceFilter,
326326
Filter::greaterThan('event_time', $start)
327327
)
328-
);
328+
)
329+
->limit(1);
329330

330331
$hardState = $hardState->first();
331332

library/Icingadb/ProvidedHook/Reporting/HostSlaReport.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ protected function createReportData()
3131

3232
protected function createReportRow($row)
3333
{
34-
if ($row->sla === null) {
35-
return null;
36-
}
37-
3834
return (new ReportRow())
3935
->setDimensions([$row->display_name])
40-
->setValues([(float) $row->sla]);
36+
->setValues([$row->sla]);
4137
}
4238
}

library/Icingadb/ProvidedHook/Reporting/ServiceSlaReport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ protected function createReportRow($row)
3333
{
3434
return (new ReportRow())
3535
->setDimensions([$row->host_display_name, $row->display_name])
36-
->setValues([(float) $row->sla]);
36+
->setValues([$row->sla]);
3737
}
3838
}

library/Icingadb/ProvidedHook/Reporting/SlaReport.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,29 @@ public function getHtml(Timerange $timerange, array $config = null)
119119
// We only have one metric
120120
$sla = $row->getValues()[0];
121121

122-
if ($sla < $threshold) {
122+
if ($sla === null) {
123+
$slaClass = 'unknown';
124+
} elseif ($sla < $threshold) {
123125
$slaClass = 'nok';
124126
} else {
125127
$slaClass = 'ok';
126128
}
127129

128-
$cells[] = Html::tag('td', ['class' => "sla-column $slaClass"], round($sla, $precision));
130+
$cells[] = Html::tag(
131+
'td',
132+
['class' => "sla-column $slaClass"],
133+
$sla === null ? t('N/A') : round($sla, $precision)
134+
);
129135

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

133139
// We only have one average
134140
$average = $data->getAverages()[0];
135-
if ($average < $threshold) {
141+
142+
if ($average === null) {
143+
$slaClass = 'unknown';
144+
} elseif ($average < $threshold) {
136145
$slaClass = 'nok';
137146
} else {
138147
$slaClass = 'ok';
@@ -144,7 +153,11 @@ public function getHtml(Timerange $timerange, array $config = null)
144153

145154
$tableRows[] = Html::tag('tr', null, [
146155
Html::tag('td', ['colspan' => count($data->getDimensions())], $total),
147-
Html::tag('td', ['class' => "sla-column $slaClass"], round($average, $precision))
156+
Html::tag(
157+
'td',
158+
['class' => "sla-column $slaClass"],
159+
$average === null ? t('N/A') : round($average, $precision)
160+
)
148161
]);
149162

150163
$table = Html::tag(

0 commit comments

Comments
 (0)