Date manipulation functions in TICKscript

Hi,

How can I do date manipulations in TICKscript?

In my alerts I want to show for what time period the batch query ran. My query is running for now and now() - 2h.

I want to show in alert that, query was run for period 10:00 to 12:00.

Hi ,

this will work for you , you may have to adapt it it to be more dynamic …
it is just an example to inspire you :slight_smile:

var message = ' The query period was {{ index .Fields "beginhour" }}:00 - {{ index .Fields "endhour" }}:00 '
...
var data = stream ...
...
data
  |eval(lambda:hour("time"))
    .as('beginhour')
    .keep()
|shift(2h)
  |eval(lambda:hour("time"))
    .as('endhour')
    .keep()
...
|alert()
         .message(message)
   //     .messageField(message)

result :

 ... =cpu:nil event_message=" The query period was 10:00 - 12:00 " data="&{cp ...

@MarcV

I get the idea.

One question. I’m using batch and if I use shift function will kapacitor fire two queries?

Hi ,

no , shift will only change the timestamp of the datapoints retrieved ,