From 2051b29656b0d3cf221217cfd748ae361bc49385 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 31 Aug 2021 16:38:56 +0200 Subject: [PATCH] run.php: Fix incorrect namespace registration for module monitoring --- run.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/run.php b/run.php index d41c9349..26158aff 100644 --- a/run.php +++ b/run.php @@ -9,11 +9,24 @@ $this->provideHook('X509/Sni'); $this->provideHook('health', 'IcingaHealth'); $this->provideHook('health', 'RedisHealth'); -if (! $this->app->getModuleManager()->hasEnabled('monitoring')) { - // Ensure we can load some classes/interfaces for compatibility with legacy hooks - $this->app->getLoader()->registerNamespace( - 'Icinga\\Module\\Monitoring', - $this->getLibDir() . '/Monitoring', - $this->getApplicationDir() - ); +if (! $this::exists('monitoring')) { + $modulePath = null; + foreach ($this->app->getModuleManager()->getModuleDirs() as $path) { + $pathToTest = join(DIRECTORY_SEPARATOR, [$path, 'monitoring']); + if (file_exists($pathToTest)) { + $modulePath = $pathToTest; + break; + } + } + + if ($modulePath === null) { + Icinga\Application\Logger::error('Unable to locate monitoring module'); + } else { + // Ensure we can load some classes/interfaces for compatibility with legacy hooks + $this->app->getLoader()->registerNamespace( + 'Icinga\\Module\\Monitoring', + join(DIRECTORY_SEPARATOR, [$modulePath, 'library', 'Monitoring']), + join(DIRECTORY_SEPARATOR, [$modulePath, 'application']) + ); + } }