Skip to main content
Question

Query about global variable behavior with event values

  • Mar 11, 2025 3:14 AM UTC
  • 25 replies
  • 182 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
  • Mar 11, 2025 4:41 AM UTC

Global Variable definition:


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

Thanks <@ULBGHDPNY&gt;Let me test it


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

<@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
  • Mar 11, 2025 4:41 AM UTC

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


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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
  • Mar 11, 2025 4:41 AM UTC

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


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

This is what I meant above with undefined.


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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
  • Mar 11, 2025 4:41 AM UTC

i'm unable to repro


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

0


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

did you commit/deploy after adding the variable?


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

the variable def needs to also be in the pack


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

you're in a pack


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

Ah ok


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

no, Packs are isolated


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

different knowledge area for Pack-specific settings


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

I see.That resolved it immediately, thanks!


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

excellent! :+1:


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

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


Jon Rust
Forum|alt.badge.img
  • Employee
  • Mar 11, 2025 4:41 AM UTC

not currently


  • Author
  • Employee
  • Mar 11, 2025 4:41 AM UTC

100%Thanks again for the help :slightly_smiling_face: