Skip to content

Commit 98862cf

Browse files
authored
Merge pull request #12 from ecwws/custom_fields
allow custom fields to be set
2 parents 16b3efc + b980f5b commit 98862cf

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ elasticsearch.
1919
such value is detected, it will be converted to iso8601 format for easier
2020
consumption of elasticsearch when dynamic mapping is used.**
2121

22-
* If a field named `timestamp` or `time` or `syslog_timestamp` exists, it will
23-
parse that field and conver it to format '%Y-%m-%dT%H:%M:%S.%L%z' then store it
24-
in `@timestamp` field. In addition, a field `fluent_converted_timestamp`
25-
is added to the object with the same value.
22+
* By default, it will check whether fields named `timestamp`, `time`, or
23+
`syslog_timestamp` exists, if so it will parse that field and conver it to
24+
format '%Y-%m-%dT%H:%M:%S.%L%z' then store it in `@timestamp` field. In
25+
addition, a field `fluent_converted_timestamp` is added to the object with
26+
the same value.
27+
28+
* (>=0.3.0) the list of fields can be overriden by setting the
29+
`timestamp_fields` parameter. It accepts a list of strings, the default is set
30+
to: `['@timestamp', 'timestamp', 'time', 'syslog_timestamp']`
2631

2732
* If none of the above field exists, it will insert current event time in
2833
'%Y-%m-%dT%H:%M:%S.%L%z' format as the `@timestamp` field. A field

fluent-plugin-elasticsearch-timestamp-check.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = "fluent-plugin-elasticsearch-timestamp-check"
3-
spec.version = "0.2.8"
3+
spec.version = "0.3.0"
44
spec.authors = ["Richard Li"]
55
spec.email = ["[email protected]"]
66
spec.description = %q{fluent filter plugin to ensure @timestamp is in proper format}

lib/fluent/plugin/filter_elasticsearch_timestamp_check.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ElasticsearchTimestampCheckFilter < Filter
77
Fluent::Plugin.register_filter('elasticsearch_timestamp_check', self)
88

99
config_param :subsecond_precision, :integer, default: 3
10+
config_param :timestamp_fields, :array, default: ['@timestamp', 'timestamp', 'time', 'syslog_timestamp'], value_type: :string
1011

1112
def configure(conf)
1213
super
@@ -33,7 +34,7 @@ def shutdown
3334
end
3435

3536
def filter(tag, time, record)
36-
%w{@timestamp timestamp time syslog_timestamp}.map do |field|
37+
@timestamp_fields.map do |field|
3738
record[field]
3839
end.compact.each do |timestamp|
3940
begin
@@ -58,6 +59,7 @@ def filter(tag, time, record)
5859
$log.debug("Timestamp parsed: #{record['@timestamp']}")
5960
break
6061
rescue ArgumentError
62+
$log.debug("#{field} (#{timestamp}) failed to parse, trying next")
6163
end
6264
end
6365

0 commit comments

Comments
 (0)