From bbb03abd953cfd240c334a5a4d145deedd9be534 Mon Sep 17 00:00:00 2001 From: Vojtech Myslivec Date: Wed, 29 Jan 2020 17:56:06 +0100 Subject: [PATCH 1/3] Add rocketchat integration to config example --- jidlobot.yml.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jidlobot.yml.example b/jidlobot.yml.example index 95c2f14..171b990 100644 --- a/jidlobot.yml.example +++ b/jidlobot.yml.example @@ -23,10 +23,14 @@ HIPCHAT_ROOM: 1 HIPCHAT_TOKEN: … HIPCHAT_COLOR: random +ROCKETCHAT_WEBHOOK: https://rocketchat/hooks/… +ROCKETCHAT_CHANNEL: channel + BACKENDS: - mattermost - mail - hipchat + - rocketchat - console ZOMATO_UA: 'Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0' From bda50508d448ea12a6e0962351d01a355949bc63 Mon Sep 17 00:00:00 2001 From: Vojtech Myslivec Date: Wed, 29 Jan 2020 17:56:30 +0100 Subject: [PATCH 2/3] Add simple Slack support --- jidlobot.py | 3 +++ jidlobot.yml.example | 3 +++ slack.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 slack.py diff --git a/jidlobot.py b/jidlobot.py index 8573313..1fdd757 100644 --- a/jidlobot.py +++ b/jidlobot.py @@ -5,6 +5,7 @@ from console import send_console from hipchat import send_hipchat from rocketchat import send_rocketchat +from slack import send_slack with open("jidlobot.yml", "r") as conf_file: config = yaml.safe_load(conf_file) @@ -20,5 +21,7 @@ send_hipchat(menus, title, config) if "rocketchat" in config["BACKENDS"]: send_rocketchat(menus, title, config) +if "slack" in config["BACKENDS"]: + send_slack(menus, title, config) if "mail" in config["BACKENDS"]: send_mail(menus, title, config) diff --git a/jidlobot.yml.example b/jidlobot.yml.example index 171b990..7c3a4a4 100644 --- a/jidlobot.yml.example +++ b/jidlobot.yml.example @@ -26,11 +26,14 @@ HIPCHAT_COLOR: random ROCKETCHAT_WEBHOOK: https://rocketchat/hooks/… ROCKETCHAT_CHANNEL: channel +SLACK_WEBHOOK: https://hooks.slack.com/services/… + BACKENDS: - mattermost - mail - hipchat - rocketchat + - slack - console ZOMATO_UA: 'Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0' diff --git a/slack.py b/slack.py new file mode 100644 index 0000000..3a22534 --- /dev/null +++ b/slack.py @@ -0,0 +1,13 @@ +import json +import re +import requests + + +def send_slack(body, subject, config): + body_slack = re.sub(r'^#### (.*)$', r'*\1*', body, flags=re.MULTILINE).replace('\n\n', '\n') + message = "*" + subject + "*\n" + body_slack + payload = json.dumps({ + "text": message + }) + + requests.post(config["SLACK_WEBHOOK"], data=payload, timeout=config["HTTP_TIMEOUT"]) From 24c14a2df1246672e9b24b9f34a62c853fe710fb Mon Sep 17 00:00:00 2001 From: Vojtech Myslivec Date: Wed, 29 Jan 2020 17:58:47 +0100 Subject: [PATCH 3/3] Add Slack to ansible role --- ansible-role/README.md | 1 + ansible-role/templates/jidlobot.yml.j2 | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ansible-role/README.md b/ansible-role/README.md index ca8a052..f843131 100644 --- a/ansible-role/README.md +++ b/ansible-role/README.md @@ -28,6 +28,7 @@ The role currently support only *mattermost* module. | .mattermost | no | | Definition of Mattermost backend (parameters are `webhook`, `channel` and `username`) | | .hipchat | no | | Definition of Hipchat backend (parameters are `url`, `room`, `token` and `color`) | | .rocketchat | no | | Definition of Rocket Chat backend (parameters are `webhook` and `channel`) | +| .slack | no | | Definition of Slack backend (the only parameter is `webhook` url) | Default `jidlobot_cron` variable is set to: ``` diff --git a/ansible-role/templates/jidlobot.yml.j2 b/ansible-role/templates/jidlobot.yml.j2 index efa975a..33e525d 100644 --- a/ansible-role/templates/jidlobot.yml.j2 +++ b/ansible-role/templates/jidlobot.yml.j2 @@ -25,6 +25,9 @@ BACKENDS: {% if jidlobot_backend.rocketchat is defined %} - rocketchat {% endif %} +{% if jidlobot_backend.slack is defined %} + - slack +{% endif %} {% if jidlobot_backend.mail is defined %} MAIL_FROM: {{ jidlobot_backend.mail.from }} @@ -58,3 +61,7 @@ HIPCHAT_COLOR: {{ jidlobot_backend.hipchat.color|default('yellow') }} ROCKETCHAT_WEBHOOK: {{ jidlobot_backend.rocketchat.webhook }} ROCKETCHAT_CHANNEL: {{ jidlobot_backend.rocketchat.channel }} {% endif %} + +{% if jidlobot_backend.slack is defined %} +SLACK_WEBHOOK: {{ jidlobot_backend.slack.webhook }} +{% endif %}