Declaring Variables in Logstash Config File

I am repeating a string (let's "abc-123") in my Logstash config file multiple times. I want to declare it as a variable at the start of config file and call this variable where required. Something like:

var my_str = "abc-123"

And use it like:
$my_str

Is there a way I can do this?

Can you give an example of how your config looks like?

You can't declare variables in the config file, but you can use Environment variables in some parts of the configuration, not everything.

Is this what you want?

    mutate {
        add_field => { "my_str" => "abc-123" }
    }

or temp variable/field:

    mutate {
        add_field => { "[@metadata][my_str]" => "abc-123" }
    }

@Rios How can we use the field my_str if we add it with the above syntax (the first one where we are not adding it into metadata)? I mean what would be the syntax to call my_str in that case?

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