Hi,
I made this watch but I'm unable to find the right values. The query returns various locations (key) and their usage (value). For each key that exceeds the gte I want to create an alert but I'm struggling to even get compare to look at the right value. I'm not sure what the correct path is. I've tried about every variation I could think of but no joy.
{
"trigger": {
"schedule": {
"interval": "30m"
}
},
"input" : {
"search" : {
"request" : {
"indices" : [ "netflow-test-*" ],
"body" : {
"size":"0",
"query": {
"bool": {
"filter": {
"match": {
"int_wan": "wan1"
}
}
}
},
"aggs": {
"range": {
"date_range": {
"field": "@timestamp",
"format": "YYYY/MM/DD, HH:mm:ss",
"ranges": [
{ "from": "now/1M" }
]
},
"aggs" : {
"switch_location" : {
"terms" : {
"field" : "location"
},
"aggs" : {
"total_bytes": {
"sum": {
"script" : "doc['in_bytes'].value + doc['out_bytes'].value"
}
}
}
}
}
}
}
}
}
}
},
"condition": {
"array_compare": {
"ctx.payload.aggregations.range.buckets": {
"path": "total_bytes",
"gte": {
"value": 1000
}
}
}
},
"actions": {
"my-logging-action": {
"logging": {
"text": "There are {{ctx.payload.aggregations.range.buckets}} documents in your index. Threshold is 10."
}
}
}
}
Example of the output of the search query
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 17046,
"max_score": 0,
"hits": []
},
"aggregations": {
"range": {
"buckets": [
{
"key": "2018/07/182, 00:00:00-*",
"from": 1530403200000,
"from_as_string": "2018/07/182, 00:00:00",
"doc_count": 17046,
"switch_location": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "locationA",
"doc_count": 17046,
"total_bytes": {
"value": 140610423
}
}
]
}
}
]
}
}
}
Output of the simulated watch
"condition": {
"type": "array_compare",
"status": "success",
"met": false,
"array_compare": {
"resolved_values": {
"ctx.payload.aggregations.range.buckets": [
{
"from_as_string": "2018/07/182, 00:00:00",
"switch_location": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 17046,
"total_bytes": {
"value": 140610423
},
"key": "locationA"
}
]
},
"doc_count": 17046,
"from": 1530403200000,
"key": "2018/07/182, 00:00:00-*"
}
]
}
}
},
"actions": []
},
"messages": []