Skip to content

Commit b538189

Browse files
committed
Handle unknown sla results correctly
1 parent 7950d89 commit b538189

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,15 @@ protected function fetchReportData(DateTime $reportStart, DateTime $reportEnd, a
179179
}
180180

181181
foreach ($reports as $name => $timeline) {
182-
$rd->addTimeline($name, $timeline);
183182
$row = (object) [];
184-
$row->sla = $timeline->getResult();
185183
$row->display_name = $name;
184+
$row->sla = $timeline->getResult();
185+
if ($row->sla === null) {
186+
// No data available
187+
continue;
188+
}
186189

190+
$rd->addTimeline($name, $timeline);
187191
if (strpos($name, static::$hostServiceSeparator) !== false) {
188192
list($host, $service) = Str::trimSplit($name, static::$hostServiceSeparator);
189193
$row->display_name = $service;
@@ -317,7 +321,8 @@ protected function fetchInitialHardState(DateTime $start, string $hostId, string
317321
$serviceFilter,
318322
Filter::greaterThan('event_time', $start)
319323
)
320-
);
324+
)
325+
->limit(1);
321326

322327
$hardState = $hardState->first();
323328

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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ 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+
$sla = 0;
124+
$slaClass = 'unknown';
125+
} elseif ($sla < $threshold) {
123126
$slaClass = 'nok';
124127
} else {
125128
$slaClass = 'ok';
@@ -132,7 +135,11 @@ public function getHtml(Timerange $timerange, array $config = null)
132135

133136
// We only have one average
134137
$average = $data->getAverages()[0];
135-
if ($average < $threshold) {
138+
139+
if ($average === null) {
140+
$average = 0;
141+
$slaClass = 'unknown';
142+
} elseif ($average < $threshold) {
136143
$slaClass = 'nok';
137144
} else {
138145
$slaClass = 'ok';

0 commit comments

Comments
 (0)