Month/Day forcing format to 2 digits in the alert log filename

Dear All,

Made progress with Tick and alerting, multiple alerts have been creating.
But simple point, ability to add date in alert log filename generated to be able to do our cleaning job later.

So far, I was able to get alertname_2020-7-8.log but expectation alertname_20200708

Is it possible to force month and day to 2 digits format?

current TICK extract of the code.

var logpath = ‘/appspath/log/alertname’
var logdate = string(year(now())) + string(month(now())) + string(day(now()))
var logname = logpath + ‘_’ + logdate + ‘.log’
|alert
.log(logname)

I think you might need to use printf

Take a look here at the examples:

https://docs.influxdata.com/kapacitor/v1.5/tick/syntax/#numerical-precision

I have a look at this already but this does not seem to work at var level but cannot save TICK script got error.

It work fine with
|alert
.message(
‘value: {{ index .Fields “value” | printf “%0.2f” }}’

but it does not work under .log() or even under var
|Alert
.log()
as follow: .log(logpath + ‘{{ index .Fields “value” | printf “%0.2f” }}’ )
your filename will show logpath and the {{ index .Fields “value” | printf “%0.2f” }} as plain text.

It’s difficult to read what you’ve tested. Could you edit your post and put the code in a </> code block?

example:
if you try below
var logdate = ‘{{index .Fields “yeardate”}}{{index .Fields “monthdate” | printf “%02d”}}{{index .Fields “daydate” | printf “%02d”}}’
var logpath = ‘/apps/kapacitor/log/cpu_alert’
var logname = logpath + ‘_’ + logdate + ‘.log’

|Alert()

.log(logname)

=> logfilename will be: cpu_alert_{{index .Fields “yeardate”}}{{index .Fields “monthdate” | printf “%02d”}}{{index .Fields “daydate” | printf “%02d”}}.log

If you try as below
var logdate = {{index .Fields “yeardate”}}{{index .Fields “monthdate” | printf “%02d”}}{{index .Fields “daydate” | printf “%02d”}}

You cannot save the script, you get this error:
invalid TICKscript: parser: unexpected unknown state, last char: ‘{’ line 34 char 15 in “logdate = {{index .F”. expected: “number”,“string”,“duration”,“identifier”,“TRUE”,“FALSE”,"==","(","-","!"

FYI
var logdate = string(year(now())) + string(monthdate) + string(day(now()))

Your Alert log filename will result of cpu_alert_202079.log