Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macros with subproperties on service-apply-rule (#2083) #2085

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

semmasu
Copy link

@semmasu semmasu commented Feb 14, 2020

Fixes #2083

In Service-Apply-Rules macros like $config.property$ should be evaluated, currently the only macro that gets evaluated is $config$

@Yoda-BZH
Copy link

Yoda-BZH commented Sep 8, 2021

I also tried to come up with a solution for this problem.

My solution was:

diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php
index ed9f6af7..c8517e64 100644
--- a/library/Director/IcingaConfig/IcingaConfigHelper.php
+++ b/library/Director/IcingaConfig/IcingaConfigHelper.php
@@ -366,6 +366,14 @@ class IcingaConfigHelper
             && ! preg_match('/\.$/', $name);
     }
 
+
+    public static function isMacroDictionnary($macroName, $whiteList = null)
+    {
+        $tokens = explode('.', $macroName);
+
+        return $whiteList === null || in_array($tokens[0], $whiteList);
+    }
+
     public static function renderStringWithVariables($string, array $whiteList = null)
     {
         $len = strlen($string);
@@ -385,7 +393,7 @@ class IcingaConfigHelper
                         // We got a macro
                         $macroName = substr($string, $start + 1, $i - $start - 1);
                         if (static::isValidMacroName($macroName)) {
-                            if ($whiteList === null || in_array($macroName, $whiteList)) {
+                            if ($whiteList === null || in_array($macroName, $whiteList) || static::isMacroDictionnary($macroName, $whiteList)) {
                                 if ($start > $offset) {
                                     $parts[] = static::renderString(
                                         substr($string, $offset, $start - $offset)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using macro sub-properties not working in Service Apply Rules
3 participants