Skip to content

Commit

Permalink
Add support for tag extraction from a hash
Browse files Browse the repository at this point in the history
extract_tags() now handles hashes properly.  Prior to this commit,
extract_tags handled hashes like this:
{["tagk1", "tagv1"]=>"true"}
  • Loading branch information
mspiegle committed Mar 31, 2016
1 parent 4e649cb commit 138a368
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/logstash/outputs/influxdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,23 @@ def extract_tags(fields)
remainder = fields.dup

tags = if remainder.has_key?("tags") && remainder["tags"].respond_to?(:inject)
remainder.delete("tags").inject({}) { |tags, tag| tags[tag] = "true"; tags }
remainder.delete("tags").inject({}) do |tags, tag|
tag.is_a?(Array) ? tags[tag[0]] = tag[1] : tags[tag] = "true"
tags
end
else
{}
end

@send_as_tags.each { |key| (tags[key] = remainder.delete(key)) if remainder.has_key?(key) }

@send_as_tags.each do |key|
if remainder.has_key?(key)
if remainder[key].is_a?(Hash)
tags.merge!(remainder.delete(key))
else
tags[key] = remainder.delete(key)
end
end
end

tags.delete_if { |key,value| value.nil? || value == "" }
remainder.delete_if { |key,value| value.nil? || value == "" }
Expand Down

0 comments on commit 138a368

Please sign in to comment.