Skip to content

Commit

Permalink
ObjectInspectionDetail: Show raw custom variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Dec 2, 2021
1 parent 71ac7c0 commit eb1ef24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions library/Icingadb/Common/ObjectInspectionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/Customvar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Widget/Detail/HostInspectionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected function assemble()
$this->createSourceLocation(),
$this->createLastCheckResult(),
$this->createAttributes(),
$this->createCustomVariables(),
$this->createRedisInfo()
]);
}
Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Widget/Detail/ServiceInspectionDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected function assemble()
$this->createSourceLocation(),
$this->createLastCheckResult(),
$this->createAttributes(),
$this->createCustomVariables(),
$this->createRedisInfo()
]);
}
Expand Down

0 comments on commit eb1ef24

Please sign in to comment.