Filebeat version: 8.12.0
The configuration of filebeat.yml is as follows
filebeat.config.inputs:
enabled: true
path: /etc/filebeat/conf.d/*.yml
processors:
- add_fields:
fields:
environment: prod
from: $(IP)
- drop_fields:
fields: ["agent.ephemeral_id","agent.name","log.offset", "host.os.codename", "_id", "host.name", "host.id", "agent.version", "ecs.version", "agent.id", "@version", "version", "fields.index", "input.type", "_type", "agent.type","beats_input_codec_plain_applied","type.keyword"]
output.logstash:
hosts: ["10.1.100.64:5045"]
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat/
name: filebeat
keepfiles: 7
permissions: 0644
In the environment variable configuration file, add the following statement:
export IP=$(hostname -I|awk '{print $1}')
And load the application using source/etc/profile
The local IP address can be obtained normally through echo $IP, but there is an error when starting the Filebeat service. The following are the logs related to the service startup error
{"log.level":"error","@timestamp":"2025-03-19T10:50:47.700+0800","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/cmd/instance.handleError","file.name":"instance/beat.go","file.line":1312},"message":"Exiting: error initializing processors: fail to unpack the add_fields configuration: missing field accessing 'processors.0.add_fields.fields.from' (source:'/etc/filebeat/filebeat.yml')","service.name":"filebeat","ecs.version":"1.6.0"}
How to write a configuration file and add the field "from" to obtain the local IP address