summaryrefslogtreecommitdiffstats
path: root/application/clicommands/HealthCommand.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
commitcd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /application/clicommands/HealthCommand.php
parentInitial commit. (diff)
downloadicingaweb2-module-director-upstream.tar.xz
icingaweb2-module-director-upstream.zip
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/clicommands/HealthCommand.php')
-rw-r--r--application/clicommands/HealthCommand.php80
1 files changed, 80 insertions, 0 deletions
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 @@
+<?php
+
+namespace Icinga\Module\Director\Clicommands;
+
+use Icinga\Module\Director\CheckPlugin\PluginState;
+use Icinga\Module\Director\Cli\Command;
+use Icinga\Module\Director\Health;
+use Icinga\Module\Director\Cli\PluginOutputBeautifier;
+
+/**
+ * Check Icinga Director Health
+ *
+ * Use this command as a CheckPlugin to monitor your Icinga Director health
+ */
+class HealthCommand extends Command
+{
+ /**
+ * Run health checks
+ *
+ * Use this command to run all or a specific set of Health Checks.
+ *
+ * USAGE
+ *
+ * icingacli director health check [options]
+ *
+ * OPTIONS
+ *
+ * --check <name> Run only a specific set of checks
+ * valid names: config, sync, import, jobs, deployment
+ * --db <name> Use a specific Icinga Web DB resource
+ * --watch <seconds> Refresh every <second>. 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);
+ }
+}