Query about global variable behavior with event values
Hi All Regarding global variables, specifically string/array types, do they need to use/compare against values from an event, or can they maintain a static value from the definition of the global variable itself? Our use case: We have the three Redis hosts in our Sentinel config. We want to implement the Cribl Redis function across multiple sources in the environment, but to manage the host list/credentials in all of those separate Redis functions would be a nightmare. Can we use global variables to store the host list (either multiple string variables or an array that can be accessed based on index value), and then reference it in the Redis function's host fields using something akin to the below? `C.vars.prod_list[0] <-- first host value` `C.vars.prod_list[1] <-- second host value` `C.vars.prod_list[2] <-- third host value` Example in Redis (doesn't work, even with all the types of access I tried, in this example the array global variable type):
Answers
-
Global Variable definition:
0 -
Try wrapping the expression in backticks and ${} around the variable:
0 -
``${C.vars.redis_sentinels_prod[1]}``
0 -
Thanks <@ULBGHDPNY> Let me test it
0 -
<@ULBGHDPNY> Testing this, using an Eval to see what the returned value might be, I get undefined. Running this in the Redis function causes no errors to appear when using non-zero based array (ie, 1-3), but using but when using zero-based notation (0-2) I get errors. 1. Are the arrays (global variables) zero-index based or non-zero based? 2. Is there a way I can test what the return value would be outside of the Redis function, if Eval is not the right way to do so?
0 -
arrays are absolutely 0-based Make sure you're in the correct worker group Are you using the pop-out to check?
0 -
Using the pop-out I also get "undefined". I'm definitely in the correct worker group. I'm assuming testing this in standalone vs sentinel should not make a difference?
0 -
the choice of deployment type would only impact the actual connection, not the variable parsing
0 -
This is what I meant above with undefined.
0 -
I'm assuming this should've returned the first value in the array referenced above, with/without the quotes?
0 -
i'm unable to repro
0 -
0
0 -
did you commit/deploy after adding the variable?
0 -
in the popout, if you remove the `[0]`do you get anything?
0 -
you're in a pack
0 -
the variable def needs to also be in the pack
0 -
Ah ok
0 -
So it can't inherit from outside of the pack?
0 -
no, Packs are isolated
0 -
different knowledge area for Pack-specific settings
0 -
I see. That resolved it immediately, thanks!
0 -
excellent!
0 -
Is there a better way to centrally manage global variables like this, including packs?
0 -
not currently
0 -
100% Thanks again for the help :slightly_smiling_face:
0