Skip to content

Commit

Permalink
Merge pull request #31 from logicmonitor/timestamp-support-added
Browse files Browse the repository at this point in the history
Timestamp support added
  • Loading branch information
ahsan13jan authored Nov 5, 2020
2 parents 16c1a67 + e985cfe commit 806ab9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fluent-plugin-lm-logs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |spec|
spec.name = "fluent-plugin-lm-logs"
spec.version = '0.0.10'
spec.version = '0.0.11'
spec.authors = ["LogicMonitor"]
spec.email = "[email protected]"
spec.summary = "LogicMonitor logs fluentd output plugin"
Expand Down
9 changes: 7 additions & 2 deletions lib/fluent/plugin/out_lm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ def process_record(tag, time, record)
else
lm_event["_lm.resourceId"] = record["_lm.resourceId"]
end

lm_event["timestamp"] = Time.at(time).utc.to_datetime.rfc3339

if record["timestamp"] != nil
lm_event["timestamp"] = record["timestamp"]
else
lm_event["timestamp"] = Time.at(time).utc.to_datetime.rfc3339
end

return lm_event
end

Expand Down
25 changes: 25 additions & 0 deletions test/plugin/test_out_lm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,29 @@ def create_valid_subject
assert_equal "LogicMonitor®", event["message"]
end
end

sub_test_case "time" do
test "timestamp passed in the record, it should use that" do
plugin = create_driver(%[
resource_mapping {"a.b": "lm_property"}
]).instance

tag = "lm.test"
time = Time.parse("2020-08-23T00:53:15+00:00").to_i
record = {"message" => "Hello from test", "timestamp2" => "2020-10-30T00:29:08.629701504Z" ,"a" => { "b" => "lm_property_value" } }

result = plugin.process_record(tag, time, record)

expected = {
"message" => "Hello from test",
"_lm.resourceId" => {
"lm_property" => "lm_property_value"
},
"timestamp" => "2020-10-30T00:29:08.629701504Z"
}

assert_equal expected, result
end
end

end

0 comments on commit 806ab9c

Please sign in to comment.