HealthCheck: add a 'deployment' section

fixes #1280
This commit is contained in:
Thomas Gelf 2017-11-10 09:59:56 +01:00
parent c5bbc5a1fa
commit 781a4db763
4 changed files with 64 additions and 27 deletions

View File

@ -25,7 +25,7 @@ class HealthCommand extends Command
* OPTIONS * OPTIONS
* *
* --check <name> Run only a specific set of checks * --check <name> Run only a specific set of checks
* valid names: config, sync, import, job * valid names: config, sync, import, job, deployment
* --db <name> Use a specific Icinga Web DB resource * --db <name> Use a specific Icinga Web DB resource
*/ */
public function checkAction() public function checkAction()

View File

@ -303,12 +303,13 @@ Health Check Plugin
You can use the Director CLI as an Icinga CheckPlugin and monitor your Director 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: Health. This will run all or just one of the following test suites:
| Name | Description | | Name | Description |
|----------|-------------------------------------------------------------------| |--------------|-------------------------------------------------------------------|
| `config` | Configuration, Schema, Migrations, Deployment Endpoint | | `config` | Configuration, Schema, Migrations |
| `sync` | All configured Sync Rules (pending changes are not a problem) | | `sync` | All configured Sync Rules (pending changes are not a problem) |
| `import` | All configured Import Sources (pending changes are not a problem) | | `import` | All configured Import Sources (pending changes are not a problem) |
| `jobs` | All configured Jobs (ignores disabled ones) | | `jobs` | All configured Jobs (ignores disabled ones) |
| `deployment` | Deployment Endpoint, last deployment outcome |
#### Usage #### Usage

View File

@ -36,6 +36,10 @@ before switching to a new version.
* FIX: Caching had an influence on context-specific Custom Variable rendering * FIX: Caching had an influence on context-specific Custom Variable rendering
when those variables contained macros (#1257) 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 1.4.1
----- -----
### Fixed issues ### Fixed issues

View File

@ -3,9 +3,11 @@
namespace Icinga\Module\Director; namespace Icinga\Module\Director;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Date\DateFormatter;
use Icinga\Module\Director\CheckPlugin\Check; use Icinga\Module\Director\CheckPlugin\Check;
use Icinga\Module\Director\CheckPlugin\CheckResults; use Icinga\Module\Director\CheckPlugin\CheckResults;
use Icinga\Module\Director\Db\Migrations; use Icinga\Module\Director\Db\Migrations;
use Icinga\Module\Director\Objects\DirectorDeploymentLog;
use Icinga\Module\Director\Objects\DirectorJob; use Icinga\Module\Director\Objects\DirectorJob;
use Icinga\Module\Director\Objects\ImportSource; use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Objects\SyncRule; use Icinga\Module\Director\Objects\SyncRule;
@ -20,10 +22,11 @@ class Health
protected $dbResourceName; protected $dbResourceName;
protected $checks = [ protected $checks = [
'config' => 'checkConfig', 'config' => 'checkConfig',
'sync' => 'checkSyncRules', 'sync' => 'checkSyncRules',
'import' => 'checkImportSources', 'import' => 'checkImportSources',
'jobs' => 'checkDirectorJobs', 'jobs' => 'checkDirectorJobs',
'deployment' => 'checkDeployments',
]; ];
public function setDbResourceName($name) public function setDbResourceName($name)
@ -58,6 +61,7 @@ class Health
$checks[] = $this->checkSyncRules(); $checks[] = $this->checkSyncRules();
$checks[] = $this->checkImportSources(); $checks[] = $this->checkImportSources();
$checks[] = $this->checkDirectorJobs(); $checks[] = $this->checkDirectorJobs();
$checks[] = $this->checkDeployments();
return $checks; return $checks;
} }
@ -133,22 +137,6 @@ class Health
$count $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; return $check;
@ -235,4 +223,48 @@ class Health
return $check; 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;
}
} }