From e8d43313b9e45b2d0ed9edd7cf7e04641b806c4c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 27 Oct 2023 10:12:16 +0200 Subject: [PATCH] ObjectInspectionDetail: Render invalid states --- .../Common/ObjectInspectionDetail.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/Icingadb/Common/ObjectInspectionDetail.php b/library/Icingadb/Common/ObjectInspectionDetail.php index 6f2472ca..b30797b4 100644 --- a/library/Icingadb/Common/ObjectInspectionDetail.php +++ b/library/Icingadb/Common/ObjectInspectionDetail.php @@ -14,6 +14,7 @@ use Icinga\Module\Icingadb\Model\Service; 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; @@ -298,13 +299,18 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement 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; } }