Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['8.2', '8.3', '8.4', '8.5']
os: ['ubuntu-latest']

steps:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3']
php: ['8.2', '8.3', '8.4', '8.5']
os: ['ubuntu-latest']

services:
Expand Down
21 changes: 21 additions & 0 deletions application/clicommands/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ public function datafieldsAction()
);
}

/**
* Export all CustomProperty definitions
*
* USAGE
*
* icingacli director export customproperties [options]
*
* OPTIONS
*
* --no-pretty JSON is pretty-printed per default
* Use this flag to enforce unformatted JSON
*/
public function custompropertiesAction()
{
$export = new ImportExport($this->db());
echo $this->renderJson(
$export->serializeAllCustomProperties(),
! $this->params->shift('no-pretty')
);
}

/**
* Export all DataList definitions
*
Expand Down
71 changes: 71 additions & 0 deletions application/clicommands/HostsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Icinga\Module\Director\Clicommands;

use Icinga\Module\Director\Cli\ObjectsCommand;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaObject;
use PDO;
use Ramsey\Uuid\Uuid;

/**
* Manage Icinga Hosts
Expand All @@ -11,4 +15,71 @@
*/
class HostsCommand extends ObjectsCommand
{
public function refreshCustomVarsAction(): void
{
foreach ($this->getObjects() as $o) {
$vars = $o->vars();
$objectProperties = $this->getObjectCustomProperties($o);

foreach ($objectProperties as $key => $property) {
$var = $vars->get($key);
if ($var && $property['uuid'] !== null) {
$var->setUuid(Uuid::fromBytes($property['uuid']));
$vars->set($key, $var);
}
}

$vars->storeToDb($o);
}
}

private function getObjectCustomProperties(IcingaObject $object)
{
if ($object->uuid === null) {
return [];
}

$type = $object->getShortTableName();

$parents = $object->listAncestorIds();

$uuids = [];
$db = $object->getConnection();

foreach ($parents as $parent) {
$uuids[] = IcingaHost::loadWithAutoIncId($parent, $db)->get('uuid');
}

$uuids[] = $object->get('uuid');
$query = $db->getDbAdapter()
->select()
->from(
['dp' => 'director_property'],
[
'key_name' => 'dp.key_name',
'uuid' => 'dp.uuid',
$type . '_uuid' => 'iop.' . $type . '_uuid',
'value_type' => 'dp.value_type',
'label' => 'dp.label',
'children' => 'COUNT(cdp.uuid)'
]
)
->join(['iop' => "icinga_$type" . '_property'], 'dp.uuid = iop.property_uuid', [])
->joinLeft(['cdp' => 'director_property'], 'cdp.parent_uuid = dp.uuid', [])
->where('iop.' . $type . '_uuid IN (?)', $uuids)
->group(['dp.uuid', 'dp.key_name', 'dp.value_type', 'dp.label'])
->order(
"FIELD(dp.value_type, 'string', 'number', 'bool', 'fixed-array',"
. " 'dynamic-array', 'fixed-dictionary', 'dynamic-dictionary')"
)
->order('children')
->order('key_name');

$result = [];
foreach ($db->getDbAdapter()->fetchAll($query, fetchMode: PDO::FETCH_ASSOC) as $row) {
$result[$row['key_name']] = $row;
}

return $result;
}
}
Loading
Loading