Skip to content

Instantly share code, notes, and snippets.

@selvakn
Created July 12, 2015 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selvakn/d743593b56dac7145efc to your computer and use it in GitHub Desktop.
Save selvakn/d743593b56dac7145efc to your computer and use it in GitHub Desktop.
ElastAlert slack integration
from elastalert.alerts import Alerter, BasicMatchString
import requests
import json
class SlackAlerter(Alerter, BasicMatchString):
required_options = set(['slack_webhook_url'])
def alert(self, matches):
for match in matches:
data = {'text': str(BasicMatchString(self.rule, match)) }
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
requests.post(self.rule['slack_webhook_url'], data=json.dumps(data), headers=headers)
# with open(self.rule['output_file_path'], "a") as output_file:
with open("/tmp/test.txt", "a") as output_file:
match_string = str(BasicMatchString(self.rule, match))
output_file.write(match_string)
def get_info(self):
return {'type': 'Slack alerter'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment