Last active
September 13, 2022 15:26
-
-
Save foxutech/30f190de39d72e6f7753774de0d67d5e to your computer and use it in GitHub Desktop.
How to enable monit alert to microsoft Teams, Check about monit with teams in https://foxutech.com monit part 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# bash script to send messages to Microsoft Teams. | |
function usage { | |
echo "ALERT!" | |
echo "description: send messages to Microsoft Teams channels" | |
echo "special notes: You'll need to change the teamsUrl variable to contain your webhook from Teams." | |
echo "usage: ${0} -b \"Message contents\"" | |
echo " -m Message body" | |
echo " -h This help info" | |
exit 1 | |
} | |
while getopts "m:h" opt; do | |
case ${opt} in | |
m) msgBody="$OPTARG" | |
;; | |
h) usage | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
# Add/Change the webhook to one you created in Teams | |
teamsUrl="{{ TEAM CHANNEL LINK }}" | |
if [[ ! "${msgBody}" ]]; then | |
echo "You didn't specify a message!" | |
usage | |
fi | |
read -d '' payLoad << EOF | |
{ | |
"title": "Monit Alert: $EVENT $SERVICE", | |
"text": "${msgBody} $MONIT_SERVICE - $MONIT_DESCRIPTION", | |
} | |
EOF | |
statusCode=$(curl \ | |
--write-out %{http_code} \ | |
--silent \ | |
--output /dev/null \ | |
-X POST \ | |
-H 'Content-type: application/json' \ | |
--data "${payLoad}" ${teamsUrl}) | |
echo ${statusCode} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment