From e7dcdd4375ea93e24a872210f1935d2a69ea77d4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 4 Oct 2022 12:38:10 +0200 Subject: [PATCH] CheckCommand: support UUIDs fixes #415 --- application/clicommands/CheckCommand.php | 54 +++++++++++++++++------- doc/84-Changelog.md | 1 + 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/application/clicommands/CheckCommand.php b/application/clicommands/CheckCommand.php index 9ba27515..303fd4e0 100644 --- a/application/clicommands/CheckCommand.php +++ b/application/clicommands/CheckCommand.php @@ -17,6 +17,7 @@ use Icinga\Module\Vspheredb\Monitoring\Health\ServerConnectionInfo; use Icinga\Module\Vspheredb\Monitoring\Health\VCenterInfo; use InvalidArgumentException; +use Ramsey\Uuid\Uuid; use function React\Promise\resolve; /** @@ -102,14 +103,22 @@ public function vcenterconnectionAction() * * USAGE * - * icingacli vspheredb check host [--name ] + * icingacli vspheredb check host [--name |--uuid ] */ public function hostAction() { $this->run(function () { - $host = $this->lookup()->findOneBy('HostSystem', [ - 'host_name' => $this->params->getRequired('name') - ]); + $uuid = $this->params->get('uuid'); + if ($uuid !== null) { + $params = [ + 'uuid' => Uuid::fromString($uuid)->getBytes() + ]; + } else { + $params = [ + 'host_name' => $this->params->getRequired('name') + ]; + } + $host = $this->lookup()->findOneBy('HostSystem', $params); $this->runChecks($host); }); } @@ -133,19 +142,26 @@ public function hostsAction() * * USAGE * - * icingacli vspheredb check vm [--name ] + * icingacli vspheredb check vm [--name |--uuid ] */ public function vmAction() { $this->run(function () { - try { - $vm = $this->lookup()->findOneBy('VirtualMachine', [ - 'object_name' => $this->params->getRequired('name') - ]); - } catch (NotFoundError $e) { + $uuid = $this->params->get('uuid'); + if ($uuid !== null) { $vm = $this->lookup()->findOneBy('VirtualMachine', [ - 'guest_host_name' => $this->params->getRequired('name') + 'uuid' => Uuid::fromString($uuid)->getBytes() ]); + } else { + try { + $vm = $this->lookup()->findOneBy('VirtualMachine', [ + 'object_name' => $this->params->getRequired('name') + ]); + } catch (NotFoundError $e) { + $vm = $this->lookup()->findOneBy('VirtualMachine', [ + 'guest_host_name' => $this->params->getRequired('name') + ]); + } } $this->runChecks($vm); }); @@ -170,14 +186,22 @@ public function vmsAction() * * USAGE * - * icingacli vspheredb check datastore [--name ] + * icingacli vspheredb check datastore [--name |--uuid ] */ public function datastoreAction() { $this->run(function () { - $datastore = $this->lookup()->findOneBy('Datastore', [ - 'object_name' => $this->params->getRequired('name') - ]); + $uuid = $this->params->get('uuid'); + if ($uuid !== null) { + $params = [ + 'uuid' => Uuid::fromString($uuid)->getBytes() + ]; + } else { + $params = [ + 'object_name' => $this->params->getRequired('name') + ]; + } + $datastore = $this->lookup()->findOneBy('Datastore', $params); $this->runChecks($datastore); }); } diff --git a/doc/84-Changelog.md b/doc/84-Changelog.md index 3f9f156c..80762008 100644 --- a/doc/84-Changelog.md +++ b/doc/84-Changelog.md @@ -39,6 +39,7 @@ place. * FEATURE: provide an --inspect parameter for Monitoring Rule checks (#397) * FEATURE: health check now checks whether the schema is up-to-date (#403) * FEATURE: daemon keep-alive in the database is being checked (#404) +* FEATURE: single object check commands now support --uuid (#415) ### Background Daemon * FEATURE: errors on shutdown are now logged (#407)