Skip to content

Commit 45b0bb9

Browse files
committed
Can now retrieve fields from event
1 parent d183d9c commit 45b0bb9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/logstash/outputs/influxdb.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class LogStash::Outputs::InfluxDB < LogStash::Outputs::Base
4444
# Both keys and values support sprintf formatting
4545
config :data_points, :validate => :hash, :default => {}, :required => true
4646

47+
# Do not use data_points. Use keys / values found in event instead.
48+
config :use_data_points, :validate => :boolean, :default => true
49+
50+
# Ignore some data_points if they are setted
51+
config :ignore_data_points, :validate => :array, :default => []
52+
4753
# Allow the override of the `time` column in the event?
4854
#
4955
# By default any column with a name of `time` will be ignored and the time will
@@ -126,12 +132,21 @@ def receive(event)
126132
# ]
127133
event_hash = {}
128134
event_hash['name'] = event.sprintf(@series)
129-
sprintf_points = Hash[@data_points.map {|k,v| [event.sprintf(k), event.sprintf(v)]}]
135+
if use_data_points
136+
sprintf_points = Hash[@data_points.map {|k,v| [event.sprintf(k), event.sprintf(v)]}]
137+
else
138+
sprintf_points = event.to_hash
139+
end
130140
if sprintf_points.has_key?('time')
131141
@logger.error("Cannot override value of time without 'allow_override_time'. Using event timestamp") unless @allow_override_time
132142
else
133143
sprintf_points['time'] = to_epoch(event.timestamp)
134144
end
145+
@ignore_data_points.each do |field|
146+
if sprintf_points.has_key?(field)
147+
sprintf_points.delete(field)
148+
end
149+
end
135150
@coerce_values.each do |column, value_type|
136151
if sprintf_points.has_key?(column)
137152
begin

0 commit comments

Comments
 (0)