From 2c01f38decd38cc2a0521aac0501f64c5d8fa395 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 3 Nov 2021 12:41:57 +0100 Subject: [PATCH] Add icingadb as OR dependecy Add only if the given module supports icingadb and has monitoring as a requirement --- application/views/scripts/config/module.phtml | 13 ++++++- .../Icinga/Application/Modules/Manager.php | 11 ++++++ library/Icinga/Application/Modules/Module.php | 39 +++++++++++++++++++ public/css/icinga/main.less | 24 ++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/application/views/scripts/config/module.phtml b/application/views/scripts/config/module.phtml index 6cadd8a90..6d41ab2f4 100644 --- a/application/views/scripts/config/module.phtml +++ b/application/views/scripts/config/module.phtml @@ -11,7 +11,8 @@ $restrictions = $module->getProvidedRestrictions(); $permissions = $module->getProvidedPermissions(); $unmetDependencies = $moduleManager->hasUnmetDependencies($module->getName()); - $state = $moduleData->enabled ? ($moduleData->loaded ? 'enabled' : 'failed') : 'disabled' + $isIcingadbSupported = isset($requiredMods['icingadb']); + $state = $moduleData->enabled ? ($moduleData->loaded ? 'enabled' : 'failed') : 'disabled'; ?> @@ -82,13 +83,18 @@
$versionString): ?> + has('icingadb', $requiredMods['icingadb'])) : ?> + + + + +
translate('Modules') ?>
escape($moduleName) ?> has($moduleName, $versionString === true ? null : $versionString)): ?> escape($versionString) ?> - escape($versionString) ?> + has('monitoring', $requiredMods['monitoring'])) ? 'class="optional"' : 'class="missing"' ?>> + escape($versionString) ?> + hasInstalled($moduleName)): ?> (translate('not installed') ?>) @@ -96,6 +102,9 @@ translate('or') ?>
diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index f137c196e..254fd3c3e 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -559,6 +559,17 @@ class Manager $module = $this->getModule($name, false); $requiredMods = $module->getRequiredModules(); + + if (isset($requiredMods['monitoring'], $requiredMods['icingadb'])) { + if (! $this->has('monitoring', $requiredMods['monitoring']) + && ! $this->has('icingadb', $requiredMods['icingadb']) + ) { + return true; + } + + unset($requiredMods['monitoring'], $requiredMods['icingadb']); + } + foreach ($requiredMods as $moduleName => $moduleVersion) { if (! $this->has($moduleName, $moduleVersion)) { return true; diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 5d742b7cd..22d1debd7 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -891,12 +891,51 @@ class Module { $requiredModules = $this->metadata()->modules ?: $this->metadata()->depends; + $hasIcingadb = isset($requiredModules['icingadb']); + if (isset($requiredModules['monitoring']) && ($this->isSupportingIcingadb() || $hasIcingadb)) { + $requiredMods = []; + $icingadbVersion = true; + if ($hasIcingadb) { + $icingadbVersion = isset($requiredModules['icingadb']) ? $requiredModules['icingadb'] : true; + unset($requiredModules['icingadb']); + } + + foreach ($requiredModules as $name => $version) { + $requiredMods[$name] = $version; + if ($name === 'monitoring') { + $requiredMods['icingadb'] = $icingadbVersion; + } + } + + $requiredModules = $requiredMods; + } + // Both modules are deprecated and their successors are now dependencies of web itself unset($requiredModules['ipl'], $requiredModules['reactbundle']); return $requiredModules; } + /** + * Check whether module supports icingadb + * + * @return bool + */ + protected function isSupportingIcingadb() + { + $icingadbSupportingModules = [ + 'cube' => '1.2.0', + 'jira' => '1.2.0', + 'graphite' => '1.2.0', + 'director' => '1.9.0', + 'toplevelview' => '0.4.0', + 'businessprocess' => '2.4.0' + ]; + + return array_key_exists($this->getName(), $icingadbSupportingModules) + && version_compare($this->getVersion(), $icingadbSupportingModules[$this->getName()], '>='); + } + /** * Fetch module metadata * diff --git a/public/css/icinga/main.less b/public/css/icinga/main.less index 74ecf419d..83e6b21fa 100644 --- a/public/css/icinga/main.less +++ b/public/css/icinga/main.less @@ -440,5 +440,29 @@ a:hover > .icon-cancel { .var(color, color-critical); font-weight: bold; } + + td { + white-space: nowrap; + + &.or-separator { + width: 100%; + transform: translate(0, 50%); + padding-left: 3em; + + &::before { + content: ""; + position: absolute; + height: 1.5em; + width: 1.5em; + left: 0.5em; + border-top: 3px solid; + border-right: 3px solid; + .var(border-top-color, "gray"); + .var(border-right-color, "gray"); + border-top-right-radius: .50em; + transform: rotate(45deg); + } + } + } } }