Skip to content

Instantly share code, notes, and snippets.

@coffeesn0b
Created January 18, 2019 01:24
Show Gist options
  • Save coffeesn0b/38e2f2c7897c62b7c946c5e4d7753650 to your computer and use it in GitHub Desktop.
Save coffeesn0b/38e2f2c7897c62b7c946c5e4d7753650 to your computer and use it in GitHub Desktop.
watcher-bad-pod-example
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"<*-riot-metrics-{now/d}>"
],
"types": [],
"body": {
"query": {
"bool": {
"must_not": [
{
"match_phrase": {
"kubernetes.container.status.reason": "ContainerCreating"
}
},
{
"match_phrase": {
"kubernetes.container.status.reason": "Completed"
}
}
],
"minimum_should_match": 0,
"filter": [
{
"exists": {
"field": "kubernetes.container.status.reason"
}
},
{
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
]
}
},
"aggs": {
"Pod_Name": {
"terms": {
"field": "kubernetes.container.name"
}
},
"loc_index": {
"terms": {
"field": "_index"
}
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 1
}
}
},
"actions": {
"OpsGenie": {
"webhook": {
"scheme": "https",
"host": "api.opsgenie.com",
"port": 443,
"method": "post",
"path": "/v2/alerts",
"params": {},
"headers": {
"Authorization": "GenieKey COWS_RULE",
"Content-Type": "application/json"
},
"body": "{\"message\":\" (Dev) Bad Pod State\",\"alias\":\"dev Pod in Bad State\",\"description\":\"Pods in cluster are in a bad state.\\n Search for kubernetes.container.status.reason != Completed or CreatingContainer\\nat #?_g=()\"}"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment