Skip to content

Commit

Permalink
fix: do not overwrite GELF internal fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Cactusbone committed Mar 7, 2023
1 parent 1aa45a4 commit dc900ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## next
- Fix: avoid GELF internal fields when removing leading underscores

## 3.3.2
- Fix: avoid panic when handling very-large exponent-notation `_@timestamp` values [#71](https://github.com/logstash-plugins/logstash-input-gelf/pull/71)

Expand Down
5 changes: 4 additions & 1 deletion lib/logstash/inputs/gelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ def remap_gelf(event)
def strip_leading_underscore(event)
# Map all '_foo' fields to simply 'foo'
event.to_hash.keys.each do |key|
move_field(event, key, key.slice(1..-1)) if key.start_with?('_')
next unless key.start_with?('_')
destination_field = key.slice(1..-1)
next if %w[version host short_message full_message timestamp level facility line file].include? destination_field # GELF inner fields
move_field(event, key, key.slice(1..-1))
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/inputs/gelf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def client_bootstrap(gelfclient, queue)
gelfclient.notify!("short_message" => message, "_level" => "foo")
e = queue.pop
expect(e.get("message")).to eq(message)
# TODO fixme, level should contain a number and _level should keep the leading underscore
expect(e.get("level")).to eq("foo")
expect(e.get("level")).to eq(1) # default
expect(e.get("_level")).to eq("foo")
end
end
end

0 comments on commit dc900ed

Please sign in to comment.