From fd372c6b6286f9d8e7fbe1c9dead719bc5127790 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 9 Aug 2018 16:05:56 +0200 Subject: [PATCH] IcingaConfig: check whether get_host succeeded... ...and warn otherwise fixes #1595 --- .../Director/IcingaConfig/IcingaConfig.php | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index fcb0152d..9c8e1253 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -533,18 +533,35 @@ globals.directorWarnOnceForThresholds = function() { return sprintf( ' -if (! globals["DirectorOverrideTemplate"]) { - const DirectorOverrideVars = "%s" const DirectorOverrideTemplate = "%s" +if (! globals[DirectorOverrideTemplate]) { + const DirectorOverrideVars = "%s" + + globals.directorWarnedOnceForServiceWithoutHost = false; + globals.directorWarnOnceForServiceWithoutHost = function() { + if (globals.directorWarnedOnceForServiceWithoutHost == false) { + globals.directorWarnedOnceForServiceWithoutHost = true + log( + LogWarning, + "config", + "Director: Custom Variable Overrides will not work in this Icinga 2 version. See Director issue #1579" + ) + } + } template Service DirectorOverrideTemplate ignore_on_error { /** * Seems that host is missing when used in a service object, works fine for * apply rules */ - if (! host) { - var host = get_host(host_name) - } + try { + if (! host) { + var host = get_host(host_name) + } + if (! host) { + globals.directorWarnOnceForServiceWithoutHost() + } + } except { globals.directorWarnOnceForServiceWithoutHost() } if (vars) { vars += host.vars[DirectorOverrideVars][name]