Hello Team,
I am trying to setup a watcher for uptime using heartbeat to trigger a mail with proper message. I've got the watcher setup and is working but the issue is that one triggered mail has more than 10 alerts so the message that I get has 10 values of the same variables in the email body. I am pasting my code here if anyone wants to have a look at it.
{
"metadata": {
"color": "red"
},
"trigger": {
"schedule": {
"interval": "5s"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": ["heartbeat*"],
"types": [],
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "monitor.status:down"
}
},
{
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
]
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gt": 0
}
}
},
"actions": {
"globo": {
"throttle_period": "15s",
"email": {
"to": "abc@gmail.com",
"subject": "Encountered {{ctx.payload.hits.total}} errors",
"body": "{{#ctx.payload.hits.hits}}{{_source.beat.hostname}}{{/ctx.payload.hits.hits}} is unable to connect to {{#ctx.payload.hits.hits}}{{_source.http.url}}{{/ctx.payload.hits.hits}}",
"attachments": {
"attached_data": {
"data": {
"format": "json"
}
}
},
"priority": "high"
}
}
}
}
The body of the mail that I am getting is given below.
host1 host1 host1 ..... host1 is unable to connect to url1 url1 url1 ..... url1
Could someone please help me in writing the watcher such that the body has just the urls that it cannot connect just once so that it looks meaningful.