Search code examples
amazon-s3logstashlogstash-groklogstash-configuration

Variables in logstash config not substituted


None of the variables in prefix are substituted - why?

It was working with on old version of logstash (1.5.4) but doesn't anymore with 2.3.

Part of the output filter in logstash.cfg (dumps to s3):

output {
  if [bucket] == "bucket1" {
     s3 {
       bucket => "bucket1"
       access_key_id => "****"
       secret_access_key => "****"
       region => "ap-southeast-2"
       prefix => "%{env}/%{year}/%{month}/%{day}/"
       size_file => 50000000 #50mb
       time_file => 1
       codec => json_lines # save log as json line (no newlines)
       temporary_directory => "/var/log/temp-logstash"
       tags => ["bucket1"]
     }
  }
  ..
}

Example dataset (taken from stdout):

{
    "random_person" => "Kenneth Cumming 2016-04-14 00:53:59.777647",
       "@timestamp" => "2016-04-14T00:53:59.917Z",
             "host" => "192.168.99.1",
             "year" => "2016",
            "month" => "04",
              "day" => "14",
              "env" => "dev",
           "bucket" => "bucket1"
}

Just in case, here is the filter:

filter {
  mutate {
    add_field => {
      "request_uri" => "%{[headers][request_path]}"
    }
  }
  grok {
    break_on_match => false # default behaviour is to stop matching after first match, we don't want that
    match => { "@timestamp" => "%{NOTSPACE:date}T%{NOTSPACE:time}Z"} # break timestamp field into date and time
    match => { "date" => "%{INT:year}-%{INT:month}-%{INT:day}"} # break date into year month and day fields
    match => { "request_uri" => "/%{WORD:env}/%{NOTSPACE:bucket}"} # break request uri into environment and bucket fields
  }
  mutate {
      remove_field => ["request_uri", "headers", "@version", "date", "time"]
  }

}

Solution

  • It's a known issue that field variables aren't allowed in 'prefix'.