jakn
August 14, 2018, 8:37am
1
I want to include triggered_time in local time zone in my actions (log, email, ...).
{{ctx.trigger.triggered_time}} shows triggered_time in UTC, but how should the example below be modified to also include triggered_time for time zone 'Europe/Copenhagen'?
PUT _xpack/watcher/watch/triggered_time
{
"trigger" : { "schedule" : { "interval" : "10s" } },
"input" : {
"search" : {
"request" : {
"indices" : [ "logs" ],
"body" : {
"query" : {
"match" : { "message": "error" }
}
}
}
}
},
"actions" : {
"log_error" : {
"logging" : {
"text" : "Triggered time (UTC):{{ctx.trigger.triggered_time}} - Triggered time (Europe/Copenhagen): ????"
}
}
}
}
spinscale
(Alexander Reelsen)
August 14, 2018, 9:12am
2
try this (note that this example fully overwrites the payload, you may want to add this to the additional payload instead)
POST _xpack/watcher/watch/_execute
{
"watch": {
"trigger": {
"schedule": {
"interval": "10s"
}
},
"input": {
"simple": {}
},
"actions": {
"log_error": {
"transform": {
"script": """
return [ 'date': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).atZone(ZoneId.of("Europe/Copenhagen")) ]"""
},
"logging": {
"text": "Triggered time (UTC):{{ctx.trigger.triggered_time}} - Triggered time (Europe/Copenhagen): {{ctx.payload.date}}"
}
}
}
}
}
jakn
August 14, 2018, 11:07am
3
Thanks.
The converted timestamp is outputted as e.g.:
2018-08-16T10:13:58.698+02:00[Europe/Copenhagen]
Is there any way to generate a string formatted like this instead?
2018-08-16 10:13:58 [Europe/Copenhagen]
Update 2018-09-17:
Last question is answered here:
https://discuss.elastic.co/t/transform-datetime-to-string/148822
system
(system)
Closed
September 11, 2018, 11:07am
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.