Skip to content

Commit

Permalink
feat: add webhook notifications for releases.
Browse files Browse the repository at this point in the history
* Add webhook notifications when a QUADS assignment is released
  to any JSON-based webhook endpoint e.g. G-chat/Slack etc.

Change-Id: I30d4d8cb73a242a04745772e7e1ead1bc51ffd5a
  • Loading branch information
sadsfae committed Feb 3, 2023
1 parent d9a377b commit d044d92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conf/quads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ ircbot_ipaddr: 192.168.0.100
ircbot_port: 5050
ircbot_channel: #yourchannel

# support for sending webhook notifications on assignment release
webhook_notify: true
webhook_url: https://chat.example.com/v1/spaces/AAABBBCCC

# wordpress wiki
wp_wiki: https://wiki.example.com
wp_username: wikiadmin
Expand Down
17 changes: 17 additions & 0 deletions quads/tools/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import logging
import os
import requests

from datetime import datetime, timedelta
from enum import Enum
Expand Down Expand Up @@ -29,10 +30,12 @@ async def create_initial_message(real_owner, cloud, cloud_info, ticket, cc):
irc_bot_ip = Config["ircbot_ipaddr"]
irc_bot_port = Config["ircbot_port"]
irc_bot_channel = Config["ircbot_channel"]
webhook_url = Config["webhook_url"]
infra_location = Config["infra_location"]
cc_users = Config["report_cc"].split(",")
for user in cc:
cc_users.append("%s@%s" % (user, Config["domain"]))

if Config["email_notify"]:
with open(os.path.join(Config.TEMPLATES_PATH, template_file)) as _file:
template = Template(_file.read())
Expand All @@ -53,6 +56,7 @@ async def create_initial_message(real_owner, cloud, cloud_info, ticket, cc):
content,
)
postman.send_email()

if Config["irc_notify"]:
try:
async with Netcat(irc_bot_ip, irc_bot_port) as nc:
Expand All @@ -69,6 +73,19 @@ async def create_initial_message(real_owner, cloud, cloud_info, ticket, cc):
logger.debug(ex)
logger.error("Beep boop netcat can't communicate with your IRC.")

if Config["webhook_notify"]:
try:
message = "QUADS: %s is now active, choo choo! - %s/assignments/#%s - %s %s" % (
cloud_info,
Config["wp_wiki"],
cloud,
real_owner,
Config["report_cc"],
)
requests.post(webhook_url, json={'text': message}, headers={'Content-Type': 'application/json'})
except Exception as ex:
logger.debug(ex)
logger.error("Beep boop we can't communicate with your webhook.")

def create_message(
cloud_obj,
Expand Down

0 comments on commit d044d92

Please sign in to comment.