From 533d2d7b775aad090305622ac9b3dfa5d01cb65d Mon Sep 17 00:00:00 2001 From: Gianluca Piccolo Date: Wed, 7 Oct 2020 17:10:19 +0200 Subject: [PATCH] Add key param to deployment status cli --- application/clicommands/ConfigCommand.php | 11 ++++++++++- library/Director/Deployment/DeploymentStatus.php | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/application/clicommands/ConfigCommand.php b/application/clicommands/ConfigCommand.php index ffe5bd00..be1a1382 100644 --- a/application/clicommands/ConfigCommand.php +++ b/application/clicommands/ConfigCommand.php @@ -4,8 +4,10 @@ namespace Icinga\Module\Director\Clicommands; use Icinga\Application\Benchmark; use Icinga\Module\Director\Cli\Command; +use Icinga\Module\Director\Core\Json; use Icinga\Module\Director\Deployment\DeploymentStatus; use Icinga\Module\Director\IcingaConfig\IcingaConfig; +use Icinga\Module\Director\Import\SyncUtils; /** * Generate, show and deploy Icinga 2 configuration @@ -130,7 +132,14 @@ class ConfigCommand extends Command $api = $this->api(); $status = new DeploymentStatus($db, $api); $result = $status->getDeploymentStatus($this->params->get('configs'), $this->params->get('activities')); + if ($key = $this->params->get('key')) { + $result = SyncUtils::getSpecificValue($result, $key); + } - printf(json_encode($result)); + if (is_string($result)) { + echo "$result\n"; + } else { + echo Json::encode($result, JSON_PRETTY_PRINT) . "\n"; + } } } diff --git a/library/Director/Deployment/DeploymentStatus.php b/library/Director/Deployment/DeploymentStatus.php index b9ca1553..f3e1891d 100644 --- a/library/Director/Deployment/DeploymentStatus.php +++ b/library/Director/Deployment/DeploymentStatus.php @@ -46,19 +46,19 @@ class DeploymentStatus ]; if ($configs) { - $result['configs'] = $this->getDeploymentStatusForConfigChecksums( + $result['configs'] = (object) $this->getDeploymentStatusForConfigChecksums( explode(',', $configs), $configChecksum ); } if ($activities) { - $result['activities'] = $this->getDeploymentStatusForActivityLogChecksums( + $result['activities'] = (object) $this->getDeploymentStatusForActivityLogChecksums( explode(',', $activities), $lastActivityLogChecksum ); } - return $result; + return (object) $result; } public function getConfigChecksumForStageName($stageName)