diff --git a/application/clicommands/HealthCommand.php b/application/clicommands/HealthCommand.php index ea28191d..19e13e49 100644 --- a/application/clicommands/HealthCommand.php +++ b/application/clicommands/HealthCommand.php @@ -25,7 +25,7 @@ class HealthCommand extends Command * OPTIONS * * --check Run only a specific set of checks - * valid names: config, sync, import, job + * valid names: config, sync, import, job, deployment * --db Use a specific Icinga Web DB resource */ public function checkAction() diff --git a/doc/60-CLI.md b/doc/60-CLI.md index 2242fe48..aee7b87c 100644 --- a/doc/60-CLI.md +++ b/doc/60-CLI.md @@ -303,12 +303,13 @@ Health Check Plugin You can use the Director CLI as an Icinga CheckPlugin and monitor your Director Health. This will run all or just one of the following test suites: -| Name | Description | -|----------|-------------------------------------------------------------------| -| `config` | Configuration, Schema, Migrations, Deployment Endpoint | -| `sync` | All configured Sync Rules (pending changes are not a problem) | -| `import` | All configured Import Sources (pending changes are not a problem) | -| `jobs` | All configured Jobs (ignores disabled ones) | +| Name | Description | +|--------------|-------------------------------------------------------------------| +| `config` | Configuration, Schema, Migrations | +| `sync` | All configured Sync Rules (pending changes are not a problem) | +| `import` | All configured Import Sources (pending changes are not a problem) | +| `jobs` | All configured Jobs (ignores disabled ones) | +| `deployment` | Deployment Endpoint, last deployment outcome | #### Usage diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index b88d741b..a0c66b45 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -36,6 +36,10 @@ before switching to a new version. * FIX: Caching had an influence on context-specific Custom Variable rendering when those variables contained macros (#1257) +### Sync +* FIX: The fix for #1223 caused a regression and broke Sync for objects without + a 'disabled' property (Sets, List members) (#1279) + 1.4.1 ----- ### Fixed issues diff --git a/library/Director/Health.php b/library/Director/Health.php index bf783e9a..f84c8178 100644 --- a/library/Director/Health.php +++ b/library/Director/Health.php @@ -3,9 +3,11 @@ namespace Icinga\Module\Director; use Icinga\Application\Config; +use Icinga\Date\DateFormatter; use Icinga\Module\Director\CheckPlugin\Check; use Icinga\Module\Director\CheckPlugin\CheckResults; use Icinga\Module\Director\Db\Migrations; +use Icinga\Module\Director\Objects\DirectorDeploymentLog; use Icinga\Module\Director\Objects\DirectorJob; use Icinga\Module\Director\Objects\ImportSource; use Icinga\Module\Director\Objects\SyncRule; @@ -20,10 +22,11 @@ class Health protected $dbResourceName; protected $checks = [ - 'config' => 'checkConfig', - 'sync' => 'checkSyncRules', - 'import' => 'checkImportSources', - 'jobs' => 'checkDirectorJobs', + 'config' => 'checkConfig', + 'sync' => 'checkSyncRules', + 'import' => 'checkImportSources', + 'jobs' => 'checkDirectorJobs', + 'deployment' => 'checkDeployments', ]; public function setDbResourceName($name) @@ -58,6 +61,7 @@ class Health $checks[] = $this->checkSyncRules(); $checks[] = $this->checkImportSources(); $checks[] = $this->checkDirectorJobs(); + $checks[] = $this->checkDeployments(); return $checks; } @@ -133,22 +137,6 @@ class Health $count )); } - })->call(function () use ($check, $db) { - $check->succeed(sprintf( - "Deployment endpoint is '%s'", - $db->getDeploymentEndpointName() - )); - })->call(function () use ($check, $db) { - $count = $db->countActivitiesSinceLastDeployedConfig(); - - if ($count === 1) { - $check->succeed('There is a single un-deployed change'); - } else { - $check->succeed(sprintf( - 'There are %d un-deployed changes', - $count - )); - } }); return $check; @@ -235,4 +223,48 @@ class Health return $check; } + + public function checkDeployments() + { + $check = new Check('Director Deployments'); + + $db = $this->getConnection(); + + $check->call(function () use ($check, $db) { + $check->succeed(sprintf( + "Deployment endpoint is '%s'", + $db->getDeploymentEndpointName() + )); + })->call(function () use ($check, $db) { + $count = $db->countActivitiesSinceLastDeployedConfig(); + + if ($count === 1) { + $check->succeed('There is a single un-deployed change'); + } else { + $check->succeed(sprintf( + 'There are %d un-deployed changes', + $count + )); + } + }); + + if (! DirectorDeploymentLog::hasDeployments($db)) { + $check->warn('Configuration has never been deployed'); + return $check; + } + + $latest = DirectorDeploymentLog::loadLatest($db); + + $ts = $latest->getDeploymentTimestamp(); + $time = DateFormatter::timeAgo($ts); + if ($latest->succeeded()) { + $check->succeed('The last Deployment was successful ' . $time); + } elseif ($latest->isPending()) { + $check->warn('The last Deployment succeeded'); + } else { + $check->error('The last Deployment failed'); + } + + return $check; + } }