Hello Community,
I working to get an alert for diskspace over 75% on server which have multiple drives (A, B, C, D). I having difficulty to in compare condition with multiple drives in a bucket. I hope below snippet of code and results will give some idea
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"metricbeat-*"
],
"types": [],
"body": {
"size": 0,
"query": {
"bool": {
"must": [
{
"exists": {
"field": "system.filesystem.used.pct"
}
},
{
"range": {
"@timestamp": {
"gte": "now-15m",
"lte": "now",
"format": "epoch_millis"
}
}
}
]
}
},
"aggs": {
"host": {
"terms": {
"field": "beat.hostname",
"size": 20,
"order": {
"pct": "desc"
}
},
"aggs": {
"pct": {
"max": {
"field": "system.filesystem.used.pct",
"script": {
"source": "doc['system.filesystem.used.pct'].value *100",
"lang": "painless"
}
}
},
"mpoint": {
"terms": {
"field": "system.filesystem.mount_point",
"size": 5,
"order": {
"pct": "desc"
}
},
"aggs": {
"pct": {
"max": {
"field": "system.filesystem.used.pct"
}
}
}
}
}
}
}
}
}
}
},
"condition": {
"script": {
"source": "ArrayList arr = ctx.payload.aggregations.bucketAgg.buckets; for (int i = 0; i < arr.length; i++) { if (arr[i]['pct'].value > params.threshold) { return true; } } return false;",
"lang": "painless",
"params": {
"threshold": 0.75
}
}
},
"actions": {
"email_1": {
"email": {
"profile": "standard",
"priority": "high",
"to": [
"test@test.com"
],
"subject": "High FS Usage on {{ctx.payload.aggregations.host.buckets.0.key}}",
"body": {
"html": "{{ctx.payload.aggregations.host.buckets.0.mpoint.buckets.0.key}} reached {{ctx.payload.aggregations.host.buckets.0.pct.value}}%"
}
}
}
}
}