Hi
I have a watcher, that should delete my logstash indices after 31 days.
I'm having trouble with the transform part of the watcher.
In the 'source' line I would like it to find the date minus 31 days.
I have the following
"transform": {
"script": {
"source": "return [ 'indexToDelete' : Instant.ofEpochMilli(ctx.trigger.scheduled_time.getMillis()).plus(Duration.ofDays(-31)) ]",
"lang": "painless"
}
}
but adding a .toString('yyyy-MM-dd') makes the watcher invoke a fail (when simulating).
Full watcher code:
{
"trigger": {
"schedule": {
"daily": {
"at": [
"00:01"
]
}
}
},
"input": {
"simple": {
"daysToKeep": 31
}
},
"condition": {
"always": {}
},
"actions": {
"delete_old_index": {
"webhook": {
"scheme": "http",
"host": "localhost",
"port": 9200,
"method": "delete",
"path": "/logstash-{{ctx.payload.indexToDelete}}",
"params": {},
"headers": {}
}
}
},
"transform": {
"script": {
"source": "return [ 'indexToDelete' : Instant.ofEpochMilli(ctx.trigger.scheduled_time.getMillis()).plus(Duration.ofDays(-31)).toString('yyyy') ]",
"lang": "painless"
}
}
}