Skip to content

Commit

Permalink
Added a filter to add fields from environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gja committed Mar 6, 2012
1 parent d595a88 commit 006d217
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/logstash/filters/environment.rb
@@ -0,0 +1,26 @@
require "logstash/filters/base"
require "logstash/namespace"

# Set fields from environment variables
class LogStash::Filters::Environment < LogStash::Filters::Base
config_name "environment"
plugin_status "stable"

# Specify a hash of fields to the environment variable
# A hash of matches of field => environment variable
config :add_field_from_env, :validate => :hash, :default => {}

public
def register
# Nothing
end # def register

public
def filter(event)
return unless filter?(event)
@add_field_from_env.each do |field, env|
event.fields[field] = ENV[env]
end
filter_matched(event)
end # def filter
end # class LogStash::Filters::Environment

0 comments on commit 006d217

Please sign in to comment.