I want to create following alert in Elastic cloud:
- Raise alert if number of unallocated shards exceeds 'x' value.
According to elastic-cloud documentation we can use the following query to Inspect unallocated shards:
GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
Can this query be implemented using a elastic watcher? I have tried to implement using following code. I am unable to figure out the condition part:
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"http": {
"request": {
"scheme": "https",
"host": "some-host",
"port": 9243,
"method": "get",
"path": "/_cluster/stats",
"params": {},
"headers": {},
"auth": {
"basic": {
"username": "user-name",
"password": "some password"
}
}
}
}
},
"condition": {
"script": {
"source": "def nodes = GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state {if (nodes > 300) {return true;}} return false;",
"lang": "painless"
}
},
"actions": {
"send_email_alert": {
"email": {
"profile": "standard",
"to": [
"[email protected]"
],
"subject": "Shard Alert",
"body": {
"text": "The number of shards per node exceeds 300. Please investigate."
}
}
}
}
}
I am new to elastic cloud and have reached an impasse.
You can use
_cluster/healthAPI call to see the number of unassigned shards. Here is all available watcher HTTP input if needed.You can use
ctxto access and use the value of any output. In your case we can usectx.payload.unassigned_shards.You can find more information about
ctxand how watcher works? in the following link. https://www.elastic.co/guide/en/elasticsearch/reference/current/how-watcher-works.htmlHere is the full example:
Here is the email as output:
Important note: Please control your
ES_URLand make sure you can see the expected output withcurlcommand before working on watcher. Eg.