watcher alert not working for multiple query with percentage calculation
code
{
"trigger": {
"schedule": {
"interval": "2m"
}
},
"input": {
"chain": {
"inputs": [
{
"first": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat-"
],
"types": [],
"body": {
"query": {
"bool": {
"must": [
{
"match_phrase": {
"http.url": "https://nexus-amazon-uat.intranet/"
}
},
{
"range": {
"@timestamp": {
"gte": "now-28d"
}
}
}
]
}
},
"_source": [
"message"
]
}
}
}
}
},
{
"second": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat-"
],
"types": ,
"body": {
"query": {
"bool": {
"must": [
{
"match_phrase": {
"http.url": "https://nexus-amazon-uat.intranet/"
}
},
{
"match": {
"monitor.status": "up"
}
},
{
"range": {
"@timestamp": {
"gte": "now-28d"
}
}
}
]
}
},
"_source": [
"message"
]
}
}
}
}
}
]
}
},
"condition": {
"script": {
"source": "ctx.vars_SLO_Percentage = ((ctx.payload.first.hits.total / ctx.payload.second.hits.total) * 100) <= 100",
"lang": "painless"
}
},
"actions": {
"email_administrator": {
"email": {
"profile": "standard",
"from": "noreply-ESaaS@xyz.com",
"to": [
"abc@xyz.com"
],
"subject": "ELASTIC STACK ALERT: SLO nexus V2 - SLO breached {{ctx.vars_SLO_Percentage}}",
"body": {
"html": "--Alerts Notification Details--
This alert triggered because a total of {{ctx.payload.second.hits.total}} Nexusv2 success hits and {{ctx.payload.first.hits.total}} nexusv2 total hits were found in the application within the last 24 hour!"
}
}
}
},
"metadata": {
"app": "dxdt",
"description": "Alert if status is down",
"env": "DX DT/Teamcity UAT"
},
"throttle_period_in_millis": 100000
}