Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement