From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- application/clicommands/HealthCommand.php | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 application/clicommands/HealthCommand.php (limited to 'application/clicommands/HealthCommand.php') diff --git a/application/clicommands/HealthCommand.php b/application/clicommands/HealthCommand.php new file mode 100644 index 0000000..1635c50 --- /dev/null +++ b/application/clicommands/HealthCommand.php @@ -0,0 +1,80 @@ + Run only a specific set of checks + * valid names: config, sync, import, jobs, deployment + * --db Use a specific Icinga Web DB resource + * --watch Refresh every . For interactive use only + */ + public function checkAction() + { + $health = new Health(); + if ($name = $this->params->get('db')) { + $health->setDbResourceName($name); + } + + if ($name = $this->params->get('check')) { + $check = $health->getCheck($name); + echo PluginOutputBeautifier::beautify($check->getOutput(), $this->screen); + + exit($check->getState()->getNumeric()); + } else { + $state = new PluginState('OK'); + $checks = $health->getAllChecks(); + + $output = []; + foreach ($checks as $check) { + $state->raise($check->getState()); + $output[] = $check->getOutput(); + } + + if ($state->getNumeric() === 0) { + echo "Icinga Director: everything is fine\n\n"; + } else { + echo "Icinga Director: there are problems\n\n"; + } + + $out = PluginOutputBeautifier::beautify(implode("\n", $output), $this->screen); + echo $out; + + if (! $this->isBeingWatched()) { + exit($state->getNumeric()); + } + } + } + + /** + * Cli should provide this information, as it shifts the parameter + * + * @return bool + */ + protected function isBeingWatched() + { + global $argv; + return in_array('--watch', $argv); + } +} -- cgit v1.2.3