Skip to content

Instantly share code, notes, and snippets.

@foxutech
Last active September 13, 2022 15:26
Show Gist options
  • Save foxutech/30f190de39d72e6f7753774de0d67d5e to your computer and use it in GitHub Desktop.
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.
#!/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