diff --git a/library/Icingadb/Common/ObjectInspectionDetail.php b/library/Icingadb/Common/ObjectInspectionDetail.php index 5aaa2a064..d2e6d4338 100644 --- a/library/Icingadb/Common/ObjectInspectionDetail.php +++ b/library/Icingadb/Common/ObjectInspectionDetail.php @@ -10,6 +10,7 @@ use Icinga\Exception\Json\JsonDecodeException; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; +use Icinga\Module\Icingadb\Widget\Detail\CustomVarTable; use Icinga\Module\Icingadb\Widget\EmptyState; use Icinga\Util\Format; use Icinga\Util\Json; @@ -198,6 +199,28 @@ protected function createAttributes(): array ]; } + protected function createCustomVariables() + { + $query = $this->object->customvar + ->columns(['name', 'value']); + + $result = []; + foreach ($query as $row) { + $result[$row->name] = $row->value; + } + + if (! empty($result)) { + $vars = new CustomVarTable($result); + } else { + $vars = new EmptyState(t('No custom variables configured.')); + } + + return [ + new HtmlElement('h2', null, Text::create(t('Custom Variables'))), + $vars + ]; + } + /** * Format the given value as a json * diff --git a/library/Icingadb/Model/Customvar.php b/library/Icingadb/Model/Customvar.php index 7019d56d7..0d8443ee0 100644 --- a/library/Icingadb/Model/Customvar.php +++ b/library/Icingadb/Model/Customvar.php @@ -64,7 +64,7 @@ public function createRelations(Relations $relations) protected function mutateValueProperty($json) { if (is_string($json)) { - $data = json_decode($json); + $data = json_decode($json, true); if ($data !== null) { $json = $data; } diff --git a/library/Icingadb/Widget/Detail/HostInspectionDetail.php b/library/Icingadb/Widget/Detail/HostInspectionDetail.php index 4603f0e7a..93b35b842 100644 --- a/library/Icingadb/Widget/Detail/HostInspectionDetail.php +++ b/library/Icingadb/Widget/Detail/HostInspectionDetail.php @@ -14,6 +14,7 @@ protected function assemble() $this->createSourceLocation(), $this->createLastCheckResult(), $this->createAttributes(), + $this->createCustomVariables(), $this->createRedisInfo() ]); } diff --git a/library/Icingadb/Widget/Detail/ServiceInspectionDetail.php b/library/Icingadb/Widget/Detail/ServiceInspectionDetail.php index 025def6a5..f29ee9bf0 100644 --- a/library/Icingadb/Widget/Detail/ServiceInspectionDetail.php +++ b/library/Icingadb/Widget/Detail/ServiceInspectionDetail.php @@ -14,6 +14,7 @@ protected function assemble() $this->createSourceLocation(), $this->createLastCheckResult(), $this->createAttributes(), + $this->createCustomVariables(), $this->createRedisInfo() ]); }