How to change the value of environment variable in logstash?

How to change the value of environment variable in logstash?

ruby {
code => "ENV[test] = 1000"
}
=> doesnot work

You can change the ENV variable that Ruby uses. Those changes will persist across multiple ruby filters. So

    ruby { code => 'ENV["test"] = "1000"' }
    ruby { code => 'puts ENV["test"]' }
    mutate { add_field => { "test" => "${test:1}" } }

will print

1000

but use the default for the environment substitution

      "test" => "1",

I am unsure whether the substitution does not work because it is happening in Java rather than Ruby, or because it has already been done before the pipeline starts executing. Either way, it does not work

    ruby { code => 'ENV.delete("PATH")' }
    ruby { code => 'puts ENV["PATH"]' }
    mutate { add_field => { "path" => "${PATH:1}" } }

will print an empty string, but set [path] to "/usr/..."

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.