Skip to content

Commit 614f6ca

Browse files
committed
initial commit
1 parent 71d940d commit 614f6ca

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Gem::Specification.new do |spec|
2+
spec.name = "fluent-plugin-elasticsearch-timestamp-check"
3+
spec.version = "0.1.0"
4+
spec.authors = ["Richard Li"]
5+
spec.email = ["[email protected]"]
6+
spec.description = %q{fluent filter plugin to ensure @timestamp is in proper format}
7+
spec.summary = %q{fluent timestamp checker filter}
8+
spec.homepage = "https://github.com/ecwws/fluent-plugin-elasticsearch-timestamp-check"
9+
spec.license = "MIT"
10+
11+
spec.files = `git ls-files`.split($/)
12+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14+
spec.require_paths = ["lib"]
15+
16+
spec.add_development_dependency "bundler", "~> 1.3"
17+
spec.add_development_dependency "rake"
18+
spec.add_development_dependency "rspec", ">= 3.0.0"
19+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Fluent
2+
class ElasticsearchTimestampCheckFilter < Filter
3+
Fluent::Plugin.register_filter('elasticsearch_timestamp_check', self)
4+
5+
def configure(conf)
6+
super
7+
require 'date'
8+
end
9+
10+
def start
11+
super
12+
end
13+
14+
def shutdown
15+
super
16+
end
17+
18+
def filter(tag, time, record)
19+
existing = record['timestamp'] || record['@timestamp']
20+
if existing
21+
record['@timestamp'] =
22+
DateTime.parse(existing).strftime('%Y-%m-%dT%H:%M:%S%z')
23+
record['fluent_converted_timestamp'] =
24+
DateTime.parse(existing).strftime('%Y-%m-%dT%H:%M:%S%z')
25+
$log.debug("Timestamp parsed: #{record['@timestamp']}")
26+
else
27+
record['@timestamp'] = Time.now.strftime('%Y-%m-%dT%H:%M:%S%z')
28+
record['fluent_added_timestamp'] =
29+
Time.now.strftime('%Y-%m-%dT%H:%M:%S%z')
30+
$log.debug("Timestamp added: #{record['@timestamp']}")
31+
end
32+
record
33+
end
34+
end
35+
end
36+

0 commit comments

Comments
 (0)