From 21a161ccfc72be022e5c5eff0500ea6d4abe6343 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Wed, 23 Apr 2025 18:19:04 +0100 Subject: [PATCH] chore (infra): add notification script --- scripts/rocketchat_notifier.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 scripts/rocketchat_notifier.sh diff --git a/scripts/rocketchat_notifier.sh b/scripts/rocketchat_notifier.sh new file mode 100755 index 0000000..b56f102 --- /dev/null +++ b/scripts/rocketchat_notifier.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Send error and success notifications to Rocket Chat channels + +# Env vars: +# --- Webhook URLs for given channel, eg $RC_WEBHOOK_TEST +# --- sourced from `.env` file in Zsh path + +# Parameters: +# --- $1 = Channel, +# --- $2 = type 'error' | 'success' +# --- $3 = Message + +# Usage: +# --- ./rocketchat_notifier.sh test 'success' 'Message goes here.' +# --- ./rocketcaht_notifier.sh test 'error' 'Message goes here.' + +declare -A CHANNEL_TO_WEBHOOK +CHANNEL_TO_WEBHOOK["backups"]=$RC_WEBHOOK_BACKUPS + +WEBHOOK=${CHANNEL_TO_WEBHOOK[$1]} + +if [ "$2" != "error" ]; then + curl -X POST \ + -H 'Content-type: application/json' \ + --data "{\"text\":\"INFO $3 \"}" \ + "$WEBHOOK" >/dev/null 2>&1 +else + curl -X POST \ + -H 'Content-type: application/json' \ + --data "{\"text\":\"ERROR \", \"attachments\": [{\"color\": \"#FF0000\", \"text\": \"$3\"}]}" \ + "$WEBHOOK" +fi