How to get additional information added by filebeat in the output of logstash

Hi
I added additional information by fields option in filebeat configuration to identify application name, 'app_id', such as,

filebeat.inputs:
- type: log
  enabled: true
  fields:
    app_id: crawler_164
......
output.logstash:
  hosts: ["10.0.0.164:5044"]

And it can be found from the log of logstash such as,

......
        "fields" => {
        "app_id" => "crawler_164"
.......

Then how to use this parameter in the output of logstash to assemble special output value.
In my case, I use a http output,

output {
    stdout { codec => rubydebug }
    http {
      url => "https://oapi.dingtalk.com/robot/send?access_token=......"
      http_method => "post"
      content_type => "application/json; charset=utf-8"
      format => "message"
      message => '{"msgtype":"text","text":{"content":"Alarm from %{app_id}:%{message}"}}'
    }
}

%{message} can be parsed correctly and %{app_id} is not. So how to use this parameter?
Thank you!

Filebeat per default will add the custom fields as a nested field of fields, so in your case, the field add_id will be added as { "fields": { "app_id": value } }, which is what you get in your logstash output.

To access this field in logstash you should use %{[fields][app_id]}.

If you want to change the default behavior you need to set the option fields_under_root in your filebeat.yml input to true.

This way the field add_id will be added to the root of the document and can be accessed as %{app_id}.

Yes. It works correctly. Thank you!

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