Watcher to delete index

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

Hi,

Can you share any failures you are seeing?
Unaware of your use case here however would Curator be a good fit for tending to indices? (https://www.elastic.co/blog/curator-3-0-released)

It's just a generic 'Watcher: An internal server error occurred' - nothing in the elastic log, so I don't know where to log for futher loginfo.

I would like to avoid Curator, so the setup can be simple and selfcontained.

if I just write '.toString()' it outputs '2017-11-04T12:26:22.487Z' - no errors

EDIT - Added full watcher JSON to case

Wow, the Curator 3.0 blog post is a bit old, seeing how version 5.4.0 is the current release. https://www.elastic.co/guide/en/elasticsearch/client/curator/current/versions.html

1 Like

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