Last active
January 21, 2019 10:42
-
-
Save mpomery/a5eb0f642e1e0e3ced1c893115cf693a to your computer and use it in GitHub Desktop.
An elasticsearch watcher that looks for a lack of data. Good to see if something has stopped happening.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"_NOTE_": "Alerts are sent if you fall below the thresholds. Set both to the same number if you only want critical messages", | |
"WarningThreshold": 10, | |
"CriticalThreshold": 5 | |
}, | |
"trigger": { | |
"schedule": { | |
"interval": "5m" | |
} | |
}, | |
"throttle_period": "58m", | |
"input": { | |
"search": { | |
"request": { | |
"indices": [ | |
"<logstash-{now/d{YYYY.MM.dd}}-index>", | |
"<logstash-{now/d-1d{YYYY.MM.dd}}-index>" | |
], | |
"body": { | |
"query": { | |
"bool": { | |
"must": [ | |
{ "match": { "field": "filter" } }, | |
{ "range": { "@timestamp": { "gte": "now-5m", "lt": "now" } } } | |
] | |
} | |
}, | |
"aggs": { | |
"count": { | |
"cardinality": { | |
"field": "FieldName" | |
} | |
}, | |
"objects": { | |
"terms": { | |
"field": "FieldName", | |
"size": 0 | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"transform": { | |
"script": "return ['servers': ctx.payload.aggregations.objects.buckets, 'count': ctx.payload.aggregations.count.value, 'alert_level': ctx.payload.aggregations.count.value < ctx.metadata.CriticalThreshold ? 'CRITICAL' : 'WARNING' ]" | |
}, | |
"condition": { | |
"compare" : { "ctx.payload.aggregations.count.value" : { "lt" : "{{ctx.metadata.WarningThreshold}}" } } | |
}, | |
"actions": { | |
"warning_alert" : { | |
"condition": { | |
"compare" : { "ctx.payload.count" : { "gte" : "{{ctx.metadata.CriticalThreshold}}" } } | |
}, | |
"webhook": { | |
"method": "POST", | |
"host": "host", | |
"port": port, | |
"path": "path", | |
"body": "" | |
} | |
}, | |
"critical_alert" : { | |
"condition": { | |
"compare" : { "ctx.payload.count" : { "lt" : "{{ctx.metadata.CriticalThreshold}}" } } | |
}, | |
"webhook": { | |
"method": "POST", | |
"host": "host", | |
"port": port, | |
"path": "path", | |
"body": "" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment