Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectInspectionDetail: Render invalid states #920

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions library/Icingadb/Common/ObjectInspectionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Icinga\Module\Icingadb\Widget\Detail\CustomVarTable;
use Icinga\Util\Format;
use Icinga\Util\Json;
use InvalidArgumentException;
use ipl\Html\BaseHtmlElement;
use ipl\Html\FormattedString;
use ipl\Html\HtmlElement;
Expand Down Expand Up @@ -298,13 +299,18 @@ private function formatMilliseconds($ms): string

private function formatState(int $state)
{
switch (true) {
case $this->object instanceof Host:
return HostStates::text($state);
case $this->object instanceof Service:
return ServiceStates::text($state);
default:
return $state;
try {
switch (true) {
case $this->object instanceof Host:
return HostStates::text($state);
case $this->object instanceof Service:
return ServiceStates::text($state);
default:
return $state;
}
} catch (InvalidArgumentException $_) {
// The Icinga 2 API sometimes delivers strange details
return (string) $state;
}
}

Expand Down