Skip to content

Commit

Permalink
CheckCommand: support UUIDs
Browse files Browse the repository at this point in the history
fixes #415
  • Loading branch information
Thomas-Gelf committed Oct 4, 2022
1 parent aeb6e57 commit e7dcdd4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
54 changes: 39 additions & 15 deletions application/clicommands/CheckCommand.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -102,14 +103,22 @@ public function vcenterconnectionAction()
*
* USAGE
*
* icingacli vspheredb check host [--name <name>]
* icingacli vspheredb check host [--name <name>|--uuid <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);
});
}
Expand All @@ -133,19 +142,26 @@ public function hostsAction()
*
* USAGE
*
* icingacli vspheredb check vm [--name <name>]
* icingacli vspheredb check vm [--name <name>|--uuid <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);
});
Expand All @@ -170,14 +186,22 @@ public function vmsAction()
*
* USAGE
*
* icingacli vspheredb check datastore [--name <name>]
* icingacli vspheredb check datastore [--name <name>|--uuid <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);
});
}
Expand Down
1 change: 1 addition & 0 deletions doc/84-Changelog.md
Expand Up @@ -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)
Expand Down

0 comments on commit e7dcdd4

Please sign in to comment.