Hi all,
I'm currently tring to get the hour of my document's timestamp in a custom 'hour' field.
I did some research and found the following solution but the resulting value in the hour field is always 5 hour higher than the actual hour of the @timestamp field.
This is the pertinent config so far:
date {
match => [ "timestring", "yyyy-MM-dd HH:mm:ss" ]
target => "@timestamp"
}
mutate {
add_field => {"[hour]" => "%{+HH}"}
add_field => {"[minute]" => "%{+mm}"}
add_field => {"[weekday]" => "%{+EEE}"}
remove_field => [ "message" ]
}
timestring is parsed by Grok from my log lines to replace the @timestamp field from the documents for accurate support of old logs. this should be pretty standard and it's working correctly.
the value returned by %{+HH} is always 5h over the hour from my timestamp. It might be because i;m in Canada/Eastern time (-5) and kibana is usting UTC.
On the other hand, maybe %{+HH} value's is not taken from the @timestamp field, which i assumed to be the default behaviour. Maybe it's returning the actual hour from the logstash service (which would also break the old-log support since the value is not from the parsed lines (not tested this yet))
I found the add_field snippet on stackoverflow (https://stackoverflow.com/questions/32222491/extract-specific-time-field-from-timestamp-in-logstash) but i have no idea hot to set a timezone or substract 5 hours to the value inside the add field clause.
Can anybody suggest a working way to get an hour/minute/day of the week field from the @timestamp of the document? Maybe i could have different target fields after the match and use some options to put only the wanted value (HH, mm, EEE) into the target fields. Or i could simply set a timezone somewhere?
Thanks!