Skip to content

Commit 4bd9a05

Browse files
committed
Can now retrieve fields from event
1 parent d183d9c commit 4bd9a05

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/logstash/outputs/influxdb.rb

Lines changed: 22 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,27 @@ 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+
# Clean values
140+
#sprintf_points.each do |key, value|
141+
#if value.is_a? String
142+
#sprintf_points[key] = value.gsub('{', '\{').gsub('}', '\}').gsub('"', '\"').gsub("'", "\'").gsub('[', '\[').gsub(']', '\]')
143+
#end
144+
#end
145+
end
130146
if sprintf_points.has_key?('time')
131147
@logger.error("Cannot override value of time without 'allow_override_time'. Using event timestamp") unless @allow_override_time
132148
else
133149
sprintf_points['time'] = to_epoch(event.timestamp)
134150
end
151+
@ignore_data_points.each do |field|
152+
if sprintf_points.has_key?(field)
153+
sprintf_points.delete(field)
154+
end
155+
end
135156
@coerce_values.each do |column, value_type|
136157
if sprintf_points.has_key?(column)
137158
begin

0 commit comments

Comments
 (0)