1

I'm trying to add an environment variable to my rsyslog template.
I tried using 'getenv()' function without any luck, I always get an empty string in return.

I'm attaching an example of my rsyslog config file, I'm using 'HOME' env variable as an example.

/etc/rsyslog.d/00-my_log.conf

set $.my_home=getenv("HOME");

template(name="json-template"
  type="list") {
    constant(value="{")
      constant(value="\",\"my_home\":\"")     property(name="$.my_home")
      constant(value="\",\"message\":\"")     property(name="msg" format="json")
    constant(value="\"}\n")
}

*.* action(type="omfile" dirCreateMode="0700" FileCreateMode="0644"
       template="json-template" File="/var/log/my_log")

/var/log/my_log

{"my_home":"","message":"my log message"}

rsyslogd: version 8.4.2

  • This works for me, but I have version 8.30.0. If you run rsyslogd -dn you will get lots of debug output. There might be an error message about getenv in there. For a normal input line I see in the debug: SET .my_home = function 'getenv' ... string 'HOME' END SET` – meuh Apr 12 at 18:48
  • Sadly I can't easily update my rsyslog version, it will require me to compile rsyslog and its dependencies to my specific Debian armv7l distribution. With rsyslogd -dn, I can see the line you mentioned, it actually defines to variable 3 times but in the end it's still an empty string. Anyway, I'll just find a workaround as this issue doesn't worth getting into a compilation session. Thanks for the help! – Hanoch Giner Apr 14 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.