Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. from elastalert.alerts import Alerter, BasicMatchString
  2. import requests
  3. import json
  4.  
  5. class SlackAlerter(Alerter, BasicMatchString):
  6. required_options = set(['slack_webhook_url'])
  7. def alert(self, matches):
  8. for match in matches:
  9. data = {'text': str(BasicMatchString(self.rule, match)) }
  10. headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
  11. requests.post(self.rule['slack_webhook_url'], data=json.dumps(data), headers=headers)
  12.  
  13. # with open(self.rule['output_file_path'], "a") as output_file:
  14. with open("/tmp/test.txt", "a") as output_file:
  15. match_string = str(BasicMatchString(self.rule, match))
  16. output_file.write(match_string)
  17.  
  18. def get_info(self):
  19. return {'type': 'Slack alerter'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement