|
2 | 2 | Tasks for notification |
3 | 3 | """ |
4 | 4 | import json |
| 5 | + |
| 6 | +import time |
5 | 7 | from future.builtins import ( # noqa |
6 | 8 | bytes, dict, int, list, object, range, str, |
7 | 9 | ascii, chr, hex, input, next, oct, open, |
@@ -64,6 +66,25 @@ def notify_hipchat(obj, ctx, level, config, security_profile): |
64 | 66 | headers=headers).raise_for_status() |
65 | 67 |
|
66 | 68 |
|
| 69 | +@app.task |
| 70 | +def notify_slack(obj, ctx, level, config, security_profile): |
| 71 | + config = decrypt_config(config, profile=security_profile) |
| 72 | + ctx.setdefault('github', True) |
| 73 | + url = config.get('url') |
| 74 | + notification = util.as_dict(obj) |
| 75 | + notification['channel'] = config.get('channel') |
| 76 | + notification['date'] = int(time.time()) |
| 77 | + msg = templatefactory.render_template( |
| 78 | + 'slack.json.jinja', notification=notification, ctx=ctx, |
| 79 | + level=level) |
| 80 | + headers = { |
| 81 | + 'content-type': 'application/json', |
| 82 | + } |
| 83 | + if url: |
| 84 | + requests.post(url, data=msg, headers=headers)\ |
| 85 | + .raise_for_status() |
| 86 | + |
| 87 | + |
67 | 88 | @app.task |
68 | 89 | def notify_github(obj, ctx, level, config, security_profile): |
69 | 90 | config = decrypt_config(config, profile=security_profile) |
@@ -96,5 +117,5 @@ def notify_github(obj, ctx, level, config, security_profile): |
96 | 117 | requests.post(status_url, data=json.dumps(data), |
97 | 118 | headers=headers).raise_for_status() |
98 | 119 | else: |
99 | | - # Github notification not sent |
| 120 | + # Github notification is not sent |
100 | 121 | pass |
0 commit comments