Class: LogStash::Filters::Environment
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::Environment
- Defined in:
- lib/logstash/filters/environment.rb
Overview
This filter stores environment variables as subfields in the ‘@metadata` field. You can then use these values in other parts of the pipeline.
Adding environment variables is as easy as:
filter {
environment {
add_metadata_from_env => { "field_name" => "ENV_VAR_NAME" }
}
}
Accessing stored environment variables is now done through the ‘@metadata` field:
["@metadata"]["field_name"]
This would reference field ‘field_name`, which in the above example references the `ENV_VAR_NAME` environment variable.
IMPORTANT: Previous versions of this plugin put the environment variables as fields at the root level of the event. Current versions make use of the ‘@metadata` field, as outlined. You have to change `add_field_from_env` in the older versions to `add_metadata_from_env` in the newer version.
Instance Method Summary collapse
Instance Method Details
#filter(event) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/logstash/filters/environment.rb', line 50 def filter(event) @add_metadata_from_env.each do |field, env| event.set("[@metadata][#{field}]", ENV[env]) end filter_matched(event) end |
#register ⇒ Object
45 46 47 |
# File 'lib/logstash/filters/environment.rb', line 45 def register # Nothing end |