diff --git a/lib/logstash/outputs/influxdb.rb b/lib/logstash/outputs/influxdb.rb index 183997c3..92329f29 100644 --- a/lib/logstash/outputs/influxdb.rb +++ b/lib/logstash/outputs/influxdb.rb @@ -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 @@ -126,12 +132,27 @@ 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 + # Clean values + #sprintf_points.each do |key, value| + #if value.is_a? String + #sprintf_points[key] = value.gsub('{', '\{').gsub('}', '\}').gsub('"', '\"').gsub("'", "\'").gsub('[', '\[').gsub(']', '\]') + #end + #end + 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