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
*
* --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
*/
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
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

View File

@ -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

View File

@ -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;
}
}