mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
[oldlogstashjson] implement encoding of @fields
This commit is contained in:
parent
be7d24983e
commit
0aaffd0736
2 changed files with 11 additions and 2 deletions
|
@ -35,7 +35,14 @@ class LogStash::Codecs::OldLogStashJSON < LogStash::Codecs::Base
|
||||||
h[key] = data[val] if data.include?(val)
|
h[key] = data[val] if data.include?(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
h.merge!(data["@fields"]) if data["@fields"].is_a?(Hash)
|
data.to_hash.each do |field, val|
|
||||||
|
# TODO: might be better to V1_TO_V0 = V0_TO_V1.invert during
|
||||||
|
# initialization than V0_TO_V1.has_value? within loop
|
||||||
|
next if V0_TO_V1.has_value?(field)
|
||||||
|
h["@fields"] = {} if h["@fields"].nil?
|
||||||
|
h["@fields"][field] = val
|
||||||
|
end
|
||||||
|
|
||||||
@on_event.call(h.to_json)
|
@on_event.call(h.to_json)
|
||||||
end # def encode
|
end # def encode
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ describe LogStash::Codecs::OldLogStashJSON do
|
||||||
it "should return old (v0) json data" do
|
it "should return old (v0) json data" do
|
||||||
data = {"type" => "t", "message" => "wat!?",
|
data = {"type" => "t", "message" => "wat!?",
|
||||||
"host" => "localhost", "path" => "/foo",
|
"host" => "localhost", "path" => "/foo",
|
||||||
"tags" => ["a","b","c"]}
|
"tags" => ["a","b","c"],
|
||||||
|
"bah" => "baz"}
|
||||||
event = LogStash::Event.new(data)
|
event = LogStash::Event.new(data)
|
||||||
got_event = false
|
got_event = false
|
||||||
subject.on_event do |d|
|
subject.on_event do |d|
|
||||||
|
@ -37,6 +38,7 @@ describe LogStash::Codecs::OldLogStashJSON do
|
||||||
insist { JSON.parse(d)["@source_host"] } == data["host"]
|
insist { JSON.parse(d)["@source_host"] } == data["host"]
|
||||||
insist { JSON.parse(d)["@source_path"] } == data["path"]
|
insist { JSON.parse(d)["@source_path"] } == data["path"]
|
||||||
insist { JSON.parse(d)["@tags"] } == data["tags"]
|
insist { JSON.parse(d)["@tags"] } == data["tags"]
|
||||||
|
insist { JSON.parse(d)["@fields"]["bah"] } == "baz"
|
||||||
got_event = true
|
got_event = true
|
||||||
end
|
end
|
||||||
subject.encode(event)
|
subject.encode(event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue