Simple Microsoft Teams push notifications notifier/alerter script
Small and simple MS Teams push notifications notifier/alerter script written in bash
Sometimes instead sending mail alerts you would like to send push notifications to your teams channel. This simple script supports few parameters and works behind corporation proxy. It can be used for different type of notifications like “Up”, “Down” and etc. You can also extend it according to your requirements.
Script code and usage
Save below code as text file: teamer.sh Give executable permissions
chmod +x teamer.sh
Script usage: teamer.sh YOUR_ALERT_SUBJECT YOUR_ALERT_DESCRIPTION ALERT_TYPE ALERT_CHANNEL_URL
*please note - that proxy variable would be picked from environmental variables, else u can manually hardcode inside script.
#!/bin/bash
#=========================================================================#
# This is Teams alerts handler author: TomC'e #
# Usage: #
# ./teamer.sh alert_subject alert_desc alert_type alert_channel_url #
#=========================================================================#
TEAMS_CHANNEL_ALERT_SUBJECT=$1
TEAMS_CHANNEL_ALERT_DESC=$2
TEAMS_CHANNEL_ALERT_TYPE=$3
TEAMS_CHANNEL_URL=$4
# Define alert type
if [[ ${TEAMS_CHANNEL_ALERT_TYPE} == "RED" ]]; then
TEAMS_CHANNEL_ALERT_COLOR_CODE="EA4300"
elif [[ ${TEAMS_CHANNEL_ALERT_TYPE} == "GREEN" ]]; then
TEAMS_CHANNEL_ALERT_COLOR_CODE="30C716"
else
echo "[-] teamer.sh can't understand param which has been passed.."
fi
# If proxy var is not empty - set proxy
if [[ -z ${PROXY_URL+x} ]]; then
echo "Proxy URL not set.. trying without proxy.."
else
export htt{p,ps}_proxy=http://${PROXY_URL}
fi
# Send alert
curl -m 5 -H "Content-Type: application/json" -d "{\"title\": \"$TEAMS_CHANNEL_ALERT_SUBJECT\", \"text\": \"$TEAMS_CHANNEL_ALERT_DESC\", \"themeColor\": \"$TEAMS_CHANNEL_ALERT_COLOR_CODE\"}" $TEAMS_CHANNEL_URL
echo "[+] teamer.sh -> alert has been sent."