Format triggered_time to local time zone in action

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):  ????"
  }
}
  }
}

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}}"
        }
      }
    }
  }
}

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

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.