Created
March 17, 2020 17:21
-
-
Save anandsunderraman/42400c1f3b449fbd7b3bff0dee7b1a19 to your computer and use it in GitHub Desktop.
Kibana watcher with slack action
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
{ | |
"trigger": { | |
"schedule": { | |
"interval": "1m" //how frequently you want the alert to run | |
} | |
}, | |
"input": { | |
"search": { | |
"request": { | |
"search_type": "query_then_fetch", | |
"indices": [ | |
"your-index*" | |
], | |
"types": [], | |
"body": { | |
"size": 10, | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match_phrase": { | |
"message": { | |
"query": "error message you would like to get alerted on" | |
} | |
} | |
} | |
], | |
"filter": [ | |
{ | |
"range": { | |
"@timestamp": { | |
"gte": "now-1m" //what is the time range | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
}, | |
"condition": { | |
"compare": { | |
"ctx.payload.hits.total": { | |
"gt": 0 //action trigger | |
} | |
} | |
}, | |
"actions": { | |
"send_trigger": { | |
"throttle_period_in_millis": 60000, | |
"transform": { | |
"script": { | |
"source": "def payload = ctx.payload; payload.msg = ctx.payload.hits.hits.0._source.message.replace('\"', ''); payload.stackTrace = ctx.payload.hits.hits.0._source.stack_trace.replace('\"', ''); return payload;", | |
"lang": "painless" | |
} | |
}, | |
"webhook": { | |
"scheme": "https", | |
"host": "hooks.slack.com", | |
"port": 443, | |
"method": "post", | |
"path": "enter/rest/of/slackhook/url", | |
"params": {}, | |
"headers": { | |
"Content-type": "application/json" | |
}, | |
"body": "{ \"channel\": \"slack-channel-name\", \"username\": \"kibana\", \"attachments\": [ { \"color\": \"danger\", \"title\": \"Your Alert title\", \"text\": \" *Reason:* ``` {{ ctx.payload.msg}} ``` \", \"footer\": \"Footer\" } ]}" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment