From 45b0bb9f774c849a46c49fb33324e86fdb33aa51 Mon Sep 17 00:00:00 2001 From: Olivier Dolbeau Date: Tue, 9 Sep 2014 11:13:29 +0200 Subject: [PATCH 1/3] Can now retrieve fields from event --- lib/logstash/outputs/influxdb.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/logstash/outputs/influxdb.rb b/lib/logstash/outputs/influxdb.rb index 183997c3..051f6a99 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,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 From 427aa999b53f5e10db73052e3c8d00c009b6a709 Mon Sep 17 00:00:00 2001 From: Olivier Dolbeau Date: Mon, 29 Sep 2014 09:56:36 +0200 Subject: [PATCH 2/3] cosmetics changes --- lib/logstash/outputs/influxdb.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/logstash/outputs/influxdb.rb b/lib/logstash/outputs/influxdb.rb index 051f6a99..4a16e0fa 100644 --- a/lib/logstash/outputs/influxdb.rb +++ b/lib/logstash/outputs/influxdb.rb @@ -42,13 +42,13 @@ class LogStash::Outputs::InfluxDB < LogStash::Outputs::Base # # Events for the same series will be batched together where possible # Both keys and values support sprintf formatting - config :data_points, :validate => :hash, :default => {}, :required => true + config :data_points, :validate => :hash, :default => {} # Do not use data_points. Use keys / values found in event instead. - config :use_data_points, :validate => :boolean, :default => true + config :columns_from_event_fields, :validate => :boolean, :default => true - # Ignore some data_points if they are setted - config :ignore_data_points, :validate => :array, :default => [] + # Ignore some columns if they are setted + config :ignore_columns, :validate => :array, :default => [] # Allow the override of the `time` column in the event? # @@ -132,7 +132,7 @@ def receive(event) # ] event_hash = {} event_hash['name'] = event.sprintf(@series) - if use_data_points + if @columns_from_event_fields sprintf_points = Hash[@data_points.map {|k,v| [event.sprintf(k), event.sprintf(v)]}] else sprintf_points = event.to_hash @@ -142,7 +142,7 @@ def receive(event) else sprintf_points['time'] = to_epoch(event.timestamp) end - @ignore_data_points.each do |field| + @ignore_columns.each do |field| if sprintf_points.has_key?(field) sprintf_points.delete(field) end From 50184ffb962ab8192cc63f3cb6a633b6bf2b53cd Mon Sep 17 00:00:00 2001 From: Olivier Dolbeau Date: Thu, 20 Nov 2014 10:50:00 +0100 Subject: [PATCH 3/3] Use not operator --- lib/logstash/outputs/influxdb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logstash/outputs/influxdb.rb b/lib/logstash/outputs/influxdb.rb index 4a16e0fa..e5ff9e1f 100644 --- a/lib/logstash/outputs/influxdb.rb +++ b/lib/logstash/outputs/influxdb.rb @@ -132,7 +132,7 @@ def receive(event) # ] event_hash = {} event_hash['name'] = event.sprintf(@series) - if @columns_from_event_fields + if !@columns_from_event_fields sprintf_points = Hash[@data_points.map {|k,v| [event.sprintf(k), event.sprintf(v)]}] else sprintf_points = event.to_hash