mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
[oldlogstashjson] simplify encoding from v1 to v0
This commit is contained in:
parent
25dc988a5d
commit
be7d24983e
2 changed files with 7 additions and 8 deletions
|
@ -30,14 +30,9 @@ class LogStash::Codecs::OldLogStashJSON < LogStash::Codecs::Base
|
|||
def encode(data)
|
||||
h = {}
|
||||
|
||||
h["@timestamp"] = data["@timestamp"]
|
||||
h["@message"] = data["message"] if data.include?("message")
|
||||
h["@source_host"] = data["source_host"] if data.include?("source_host")
|
||||
# Convert the old logstash schema to the new one.
|
||||
basics = %w(@timestamp @message @source_host @source_path @source
|
||||
@tags @type)
|
||||
basics.each do |key|
|
||||
h[key] = data[key] if data.include?(key)
|
||||
# Convert the new logstash schema to the old one.
|
||||
V0_TO_V1.each do |key, val|
|
||||
h[key] = data[val] if data.include?(val)
|
||||
end
|
||||
|
||||
h.merge!(data["@fields"]) if data["@fields"].is_a?(Hash)
|
||||
|
|
|
@ -32,7 +32,11 @@ describe LogStash::Codecs::OldLogStashJSON do
|
|||
got_event = false
|
||||
subject.on_event do |d|
|
||||
insist { JSON.parse(d)["@timestamp"] } != nil
|
||||
insist { JSON.parse(d)["@type"] } == data["type"]
|
||||
insist { JSON.parse(d)["@message"] } == data["message"]
|
||||
insist { JSON.parse(d)["@source_host"] } == data["host"]
|
||||
insist { JSON.parse(d)["@source_path"] } == data["path"]
|
||||
insist { JSON.parse(d)["@tags"] } == data["tags"]
|
||||
got_event = true
|
||||
end
|
||||
subject.encode(event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue