Skip to main content
Question

Query about global variable behavior with event values

  • March 11, 2025
  • 25 replies
  • 17 views

Hi AllRegarding 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):

25 replies

  • Author
  • Employee
  • March 11, 2025

Global Variable definition:


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

Try wrapping the expression in backticks and ${} around the variable:


  • Author
  • Employee
  • March 11, 2025

Thanks <@ULBGHDPNY&gt;Let me test it


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

``${C.vars.redis_sentinels_prod[1]}``


  • Author
  • Employee
  • March 11, 2025

<@ULBGHDPNY&gt;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?


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

arrays are absolutely 0-basedMake sure you're in the correct worker groupAre you using the pop-out to check?


  • Author
  • Employee
  • March 11, 2025

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?


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

the choice of deployment type would only impact the actual connection, not the variable parsing


  • Author
  • Employee
  • March 11, 2025

This is what I meant above with undefined.


  • Author
  • Employee
  • March 11, 2025

I'm assuming this should've returned the first value in the array referenced above, with/without the quotes?


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

i'm unable to repro


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

0


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

did you commit/deploy after adding the variable?


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

the variable def needs to also be in the pack


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

you're in a pack


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

in the popout, if you remove the `[0]`do you get anything?


  • Author
  • Employee
  • March 11, 2025

Ah ok


  • Author
  • Employee
  • March 11, 2025

So it can't inherit from outside of the pack?


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

no, Packs are isolated


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

different knowledge area for Pack-specific settings


  • Author
  • Employee
  • March 11, 2025

I see.That resolved it immediately, thanks!


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

excellent! :+1:


  • Author
  • Employee
  • March 11, 2025

Is there a better way to centrally manage global variables like this, including packs?


Jon Rust
Forum|alt.badge.img
  • Employee
  • March 11, 2025

not currently


  • Author
  • Employee
  • March 11, 2025

100%Thanks again for the help :slightly_smiling_face: