|
|
|
@ -5,9 +5,9 @@ from email import message_from_file |
|
|
|
|
|
|
|
|
|
import json |
|
|
|
|
import os |
|
|
|
|
import requests |
|
|
|
|
import sys |
|
|
|
|
import syslog |
|
|
|
|
import urllib.request |
|
|
|
|
|
|
|
|
|
hook_url = os.environ.get('SLACK_WEBHOOK_URL') |
|
|
|
|
|
|
|
|
@ -35,19 +35,22 @@ def send_to_slack(fr,title,body): |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
response = requests.post( |
|
|
|
|
req = urllib.request.Request( |
|
|
|
|
hook_url, |
|
|
|
|
data=json.dumps(slack_data), |
|
|
|
|
headers={'Content-Type': 'application/json'} |
|
|
|
|
data=json.dumps(slack_data).encode(), |
|
|
|
|
headers={'Content-Type': 'application/json'}, |
|
|
|
|
method='POST' |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if response.status_code != 200: |
|
|
|
|
with urllib.request.urlopen(req) as response: |
|
|
|
|
if response.status != 200: |
|
|
|
|
encoded_text = response.read() |
|
|
|
|
syslog.syslog( |
|
|
|
|
syslog.LOG_ERR, "Couldn't send webhook to slack: resp %s %s" % (response.status_code, response.text) |
|
|
|
|
syslog.LOG_ERR, "Couldn't send webhook to slack: resp %s %s" % (response.status, encoded_text) |
|
|
|
|
) |
|
|
|
|
raise ValueError( |
|
|
|
|
'Request to slack returned an error %s, the response is:\n%s' |
|
|
|
|
% (response.status_code, response.text) |
|
|
|
|
% (response.status, encoded_text) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|