How to parse field named "host" (or any other field which is reserved by filebeat) in JSON structured log?



I am trying to publish messages into Kafka using filebeat 6.3.0. My log files has single line, JSON structured logs, like;


I am using filebeat JSON options like;

json.keys_under_root: true
json.overwrite_keys: true
json.add_error_key: false

As you can see, I have a host field in my logs. But, when it comes to kafka / output, it comes like;

"host": {
	"name": "linuxbox"

which is the name of my machine. But I want it to be as shown in the log file. How can I fix this?


(Jaime Soriano) #2

Hi @elasticheart,

Indeed host is a field managed by each Beat, so it is not recommended to use it in your custom events. Would json.keys_under_root: false be an option for you?

If you need to keep the fields in the top level in any case there is a way to circumvent the override of reserved fields taking advantage of current implementation.

In the output pipeline, input-specific processors are executed first, then "builtin" fields like are added, and finally global processors are executed. So you can rename fields so they are not overwritten by the builtin fields, and then if you want you can overwrite the builtin field.

For that you need to add a processor to prevent your value to be overwritten, e.g:

- type: log
  - rename:
      - from: "host"
        to: "host.srcname"

With this your field will be kept on host.srcname. If you want to override the field added by filebeat, you can add this top-level configuration:

- drop_fields:
      has_fields: ['host.srcname']
    fields: ['']
- rename:
      has_fields: ['host.srcname']
    - from: 'host.srcname'
      to: ''

But remember that this option depends on current implementation, and the way these builtin fields are managed can change in the future.

(system) #3

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