Skip to content

Commit

Permalink
Can now retrieve fields from event
Browse files Browse the repository at this point in the history
  • Loading branch information
odolbeau committed Sep 9, 2014
1 parent d183d9c commit 45b0bb9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/logstash/outputs/influxdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class LogStash::Outputs::InfluxDB < LogStash::Outputs::Base
# Both keys and values support sprintf formatting
config :data_points, :validate => :hash, :default => {}, :required => true

# Do not use data_points. Use keys / values found in event instead.
config :use_data_points, :validate => :boolean, :default => true

# Ignore some data_points if they are setted
config :ignore_data_points, :validate => :array, :default => []

# Allow the override of the `time` column in the event?
#
# By default any column with a name of `time` will be ignored and the time will
Expand Down Expand Up @@ -126,12 +132,21 @@ def receive(event)
# ]
event_hash = {}
event_hash['name'] = event.sprintf(@series)
sprintf_points = Hash[@data_points.map {|k,v| [event.sprintf(k), event.sprintf(v)]}]
if use_data_points
sprintf_points = Hash[@data_points.map {|k,v| [event.sprintf(k), event.sprintf(v)]}]
else
sprintf_points = event.to_hash
end
if sprintf_points.has_key?('time')
@logger.error("Cannot override value of time without 'allow_override_time'. Using event timestamp") unless @allow_override_time
else
sprintf_points['time'] = to_epoch(event.timestamp)
end
@ignore_data_points.each do |field|
if sprintf_points.has_key?(field)
sprintf_points.delete(field)
end
end
@coerce_values.each do |column, value_type|
if sprintf_points.has_key?(column)
begin
Expand Down

0 comments on commit 45b0bb9

Please sign in to comment.