Is formating time in InfluxDB/Kapacitor possible?

Hello!

I’m using Kapacitor 1.3 and InfluxDB 1.2.

I would like to write a .message() an http link giving the path to a Grafana panel.

The problem is the two time formats are completely different: {{ .Time }} in my TICKscript gives a time formatted like 2017-07-21 14:56:00 +0000 UTC while Grafana uses in its URL unix epoc format like 1500649601.

Below the relevant part of my script:

// Deadman
  |deadman(1.0, 2m)
        .id('deadman')
        .idTag('id')
    	.levelTag('level')
    	.message('http://localhost:3000/dashboard/db/tacker_alert?orgId=1&from={{ .Time }}-3h&to={{ .Time }}')
        .log('/tmp/deadman_alert.log')

Is that possible to convert from one format to another in the TICKscript?

Thanks!

It not currently possible but has been requested before.

I see that you just found that issue…

Ok @nathaniel thank you!
I’ll try a UDF then

I’ve used following workaround to get the timestamp in unix time:
using eval and lambda to create new field called timestamp and then you can reference to it as to any other field in the alert.message():

|eval(lambda: int(unixNano("time")/1000000000))
    .as('timestamp')

|alert()
    .message("Current timestamp is {{ index .Fields "timestamp" }}")

Hope this saves some time to others.

2 Likes