Skip to main content
Solved

Python Script Fails To Access Environment Variable Set In Collector Script

  • January 31, 2026
  • 2 replies
  • 3 views

WayneG
This message originated from Cribl Community Slack.
Click here to view the original link.

I can't figure out how to use an environment variable that has been set in collector script running a python script. I have tried prefixing the environment variable with $, using just the variable name as set, using envVar., c.Vars. as well as a few other ways. Why isn't this documented somewhere? A screenshot of my env variables and their use in the python script are provided in the graphic below.

Links for this message:
image.png

Best answer by Jon Rust

If you were using bash (or similar shell) you could reference them with $VARNAME. Since you're using python, you'll need some extra work. I think the os module is needed?
import os
somename = os.environ.get("MY_ENV_VAR","default_value_here_in_case_undefined")
print(somename)
Edit: cleaned up the python call

2 replies

Jon Rust
Forum|alt.badge.img
  • Employee
  • Answer
  • January 31, 2026
If you were using bash (or similar shell) you could reference them with $VARNAME. Since you're using python, you'll need some extra work. I think the os module is needed?
import os
somename = os.environ.get("MY_ENV_VAR","default_value_here_in_case_undefined")
print(somename)
Edit: cleaned up the python call

WayneG
  • Author
  • New Participant
  • January 31, 2026
Thanks Jon! That got it.