Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: added option to check a single import source or sync rule by name #2698

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions application/clicommands/HealthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HealthCommand extends Command
*
* --check <name> Run only a specific set of checks
* valid names: config, sync, import, jobs, deployment
* --name <name> Name of a single Import Source or Sync Rule
* --db <name> Use a specific Icinga Web DB resource
* --watch <seconds> Refresh every <second>. For interactive use only
*/
Expand All @@ -37,9 +38,21 @@ public function checkAction()
$health->setDbResourceName($name);
}

if ($this->params->get('name')){
log1-c marked this conversation as resolved.
Show resolved Hide resolved
$check_name = $this->params->get('name');
} else {
$check_name = null;
}


if ($name = $this->params->get('check')) {
$check = $health->getCheck($name);
log1-c marked this conversation as resolved.
Show resolved Hide resolved
echo PluginOutputBeautifier::beautify($check->getOutput(), $this->screen);
if (is_null($check_name)){
$check = $health->getCheck($name);
echo PluginOutputBeautifier::beautify($check->getOutput(), $this->screen);
} else {
$check = $health->getCheck($name, $check_name);
echo PluginOutputBeautifier::beautify($check->getOutput(), $this->screen);
}

exit($check->getState()->getNumeric());
} else {
Expand Down
19 changes: 14 additions & 5 deletions library/Director/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ public function setDbResourceName($name)
return $this;
}

public function getCheck($name)
public function getCheck($name,$check_name = null)
log1-c marked this conversation as resolved.
Show resolved Hide resolved
{
if (array_key_exists($name, $this->checks)) {
$func = $this->checks[$name];
log1-c marked this conversation as resolved.
Show resolved Hide resolved
$check = $this->$func();
if(!$check_name){
log1-c marked this conversation as resolved.
Show resolved Hide resolved
$func = $this->checks[$name];
$check = $this->$func();
} else {
$func = $this->checks[$name];
$check = $this->$func($check_name);
}

} else {
$check = new CheckResults('Invalid Parameter');
$check->fail("There is no check named '$name'");
Expand Down Expand Up @@ -142,7 +148,7 @@ public function checkConfig()
return $check;
}

public function checkSyncRules()
public function checkSyncRules($check_name = null)
{
$check = new CheckResults('Sync Rules');
$rules = SyncRule::loadAll($this->getConnection(), null, 'rule_name');
Expand All @@ -155,6 +161,7 @@ public function checkSyncRules()
foreach ($rules as $rule) {
$state = $rule->get('sync_state');
$name = $rule->get('rule_name');
if( isset($check_name) && $name !== $check_name){ continue; }
log1-c marked this conversation as resolved.
Show resolved Hide resolved
if ($state === 'failing') {
$message = $rule->get('last_error_message');
$check->fail("'$name' is failing: $message");
Expand All @@ -170,7 +177,7 @@ public function checkSyncRules()
return $check;
}

public function checkImportSources()
public function checkImportSources($check_name = null)
{
$check = new CheckResults('Import Sources');
$sources = ImportSource::loadAll($this->getConnection(), null, 'source_name');
Expand All @@ -183,6 +190,8 @@ public function checkImportSources()
foreach ($sources as $src) {
$state = $src->get('import_state');
$name = $src->get('source_name');
if(isset($check_name) && $name !== $check_name){ continue; }

if ($state === 'failing') {
$message = $src->get('last_error_message');
$check->fail("'$name' is failing: $message");
Expand Down