Bigbad
(Bigbad)
August 18, 2021, 8:44am
1
Hello,
I want to have another date field in Europe/Paris timezone with logstash date filter.
filter {
mutate {
add_field =>{
"my_date" => "%{@timestamp}"
}
}
date {
match => ["my_date", "yyyy-MM-dd'T'HH:mm:ss.SSSZ"]
timezone => "Europe/paris"
target => "my_date"
}
}
The result is
"my_date" => 2021-08-18T08:36:05.569Z,
"@timestamp" => 2021-08-18T08:36:05.569Z,
What I want is :
"my_date" => 2021-08-18T10:36:05.569Z,
"@timestamp" => 2021-08-18T08:36:05.569Z,
Thank
Badger
August 18, 2021, 1:51pm
2
If the timestamp has a Z at the end then it is in UTC and the timezone option is ignored. You can use mutate+gsub to remove it.
Bigbad
(Bigbad)
August 19, 2021, 4:07pm
3
Thank you for you response.
I use mutate and gsub and extract just "yyyy-MM-dd'T'HH:mm:ss.SSSZ" value
I use the next config
date {
match => ["my_date", "yyyy-MM-dd'T'HH:mm:ss"]
timezone => "Europe/paris"
target => "my_date1"
}
and the result is
"my_date" => 2021-08-18T06:36:05,
"my_date1" => 2021-08-18T08:36:05.569Z,
different to what I really want
"my_date1" => 2021-08-18T10:36:05,
"my_date" => 2021-08-18T08:36:05.569Z,
Badger
August 19, 2021, 5:44pm
4
A date filter always converts a date to UTC. If you tell it the timestamp is in Europe/Paris then it will subtract two hours from the timestamp to do that. I get
"my_date" => "2021-08-18T06:36:05",
"my_date1" => 2021-08-18T04:36:05.000Z,
If you want to invert the delta, but keep the start/end dates for DST then this might help
mutate { add_field => { "[my_date]" => "2021-08-18T06:36:05" } }
date {
match => ["my_date", "yyyy-MM-dd'T'HH:mm:ss"]
timezone => "UTC"
target => "my_date1"
}
date {
match => ["my_date", "yyyy-MM-dd'T'HH:mm:ss"]
timezone => "Europe/Paris"
target => "my_date2"
}
ruby {
code => '
t1 = event.get("my_date1").to_f
t2 = event.get("my_date2").to_f
if t1 and t2
offset = t1 - t2
event.set("otherTimestamp", LogStash::Timestamp.new(Time.at(t1 + offset)))
end
'
}
which produces
"my_date2" => 2021-08-18T04:36:05.000Z,
"my_date" => "2021-08-18T06:36:05",
"my_date1" => 2021-08-18T06:36:05.000Z,
"otherTimestamp" => 2021-08-18T08:36:05.000Z
Bigbad
(Bigbad)
August 19, 2021, 6:25pm
5
Thank you @Badger ,
It works perfectly
system
(system)
Closed
September 16, 2021, 6:26pm
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.