summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Widget/HealthCheckPluginOutput.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 /library/Director/Web/Widget/HealthCheckPluginOutput.php
parentInitial commit. (diff)
downloadicingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz
icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Web/Widget/HealthCheckPluginOutput.php')
-rw-r--r--library/Director/Web/Widget/HealthCheckPluginOutput.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/library/Director/Web/Widget/HealthCheckPluginOutput.php b/library/Director/Web/Widget/HealthCheckPluginOutput.php
new file mode 100644
index 0000000..83ac102
--- /dev/null
+++ b/library/Director/Web/Widget/HealthCheckPluginOutput.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Widget;
+
+use ipl\Html\Html;
+use ipl\Html\HtmlDocument;
+use ipl\Html\HtmlString;
+use gipfl\Translation\TranslationHelper;
+use Icinga\Module\Director\CheckPlugin\PluginState;
+use Icinga\Module\Director\Health;
+
+class HealthCheckPluginOutput extends HtmlDocument
+{
+ use TranslationHelper;
+
+ /** @var Health */
+ protected $health;
+
+ /** @var PluginState */
+ protected $state;
+
+ public function __construct(Health $health)
+ {
+ $this->state = new PluginState('OK');
+ $this->health = $health;
+ $this->process();
+ }
+
+ protected function process()
+ {
+ $checks = $this->health->getAllChecks();
+
+ foreach ($checks as $check) {
+ $this->add([
+ $title = Html::tag('h1', $check->getName()),
+ $ul = Html::tag('ul', ['class' => 'health-check-result'])
+ ]);
+
+ $problems = $check->getProblemSummary();
+ if (! empty($problems)) {
+ $badges = Html::tag('span', ['class' => 'title-badges']);
+ foreach ($problems as $state => $count) {
+ $badges->add(Html::tag('span', [
+ 'class' => ['badge', 'state-' . strtolower($state)],
+ 'title' => sprintf(
+ $this->translate('%s: %d'),
+ $this->translate($state),
+ $count
+ ),
+ ], $count));
+ }
+ $title->add($badges);
+ }
+
+ foreach ($check->getResults() as $result) {
+ $state = $result->getState()->getName();
+ $ul->add(Html::tag('li', [
+ 'class' => 'state state-' . strtolower($state)
+ ], $this->highlightNames($result->getOutput()))->setSeparator(' '));
+ }
+ $this->state->raise($check->getState());
+ }
+ }
+
+ public function getState()
+ {
+ return $this->state;
+ }
+
+ protected function colorizeState($state)
+ {
+ return Html::tag('span', ['class' => 'badge state-' . strtolower($state)], $state);
+ }
+
+ protected function highlightNames($string)
+ {
+ $string = Html::escape($string);
+ return new HtmlString(preg_replace_callback(
+ "/'([^']+)'/",
+ [$this, 'highlightName'],
+ $string
+ ));
+ }
+
+ protected function highlightName($match)
+ {
+ return '"' . Html::tag('strong', $match[1]) . '"';
+ }
+
+ protected function getColorized($match)
+ {
+ return $this->colorizeState($match[1]);
+ }
+}