Created
July 14, 2020 05:19
-
-
Save nkn1111/71f7646e3c8b635e478e0296afa91a05 to your computer and use it in GitHub Desktop.
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 | |
# MsTeams notification script for Munin | |
# Nirmal Nath (@nkn1111) | |
# | |
# We use the slack module to post the alerts to Msteams webhook endpoint | |
# To use: | |
# 1) Create a new incoming webhook for MsTeams | |
# 2) Edit the Webhook URL for the variable | |
# 3) Add the following to your munin configuration: | |
# | |
# # -- Slack contact configuration | |
# contact.slack.command MUNIN_SERVICESTATE="${var:worst}" MUNIN_HOST="${var:host}" MUNIN_SERVICE="${var:graph_title}" MUNIN_GROUP=${var:group} MUNIN_CONSOLE="https://munin.com/admin/munin/problems.html" /usr/local/bin/munin_msteams_notify.sh | |
# contact.slack.always_send warning critical | |
# # note: This has to be on one line for munin to parse properly | |
# contact.slack.text ${if:cfields \u000A* CRITICALs:${loop<,>:cfields ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields \u000A* WARNINGs:${loop<,>:wfields ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields \u000A* UNKNOWNs:${loop<,>:ufields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields \u000A* OKs:${loop<,>:fofields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.} | |
MSTEAMS_WEBHOOK_URL="https://outlook.office.com/webhook/your/msteams/webhook/endpoint" | |
input=`cat` | |
#Set the message icon based on service state | |
if [ "$MUNIN_SERVICESTATE" = "CRITICAL" ] | |
then | |
ICON=":exclamation:" | |
COLOR="8C1A1A" | |
elif [ "$MUNIN_SERVICESTATE" = "WARNING" ] | |
then | |
ICON=":warning:" | |
COLOR="FFA500" | |
elif [ "$MUNIN_SERVICESTATE" = "ok" ] | |
then | |
ICON=":white_check_mark:" | |
COLOR="2DC72D" | |
elif [ "$MUNIN_SERVICESTATE" = "OK" ] | |
then | |
ICON=":white_check_mark:" | |
COLOR="2DC72D" | |
elif [ "$MUNIN_SERVICESTATE" = "UNKNOWN" ] | |
then | |
ICON=":question:" | |
COLOR="808080" | |
else | |
ICON=":white_medium_square:" | |
COLOR="808080" | |
fi | |
# Generate the JSON payload | |
PAYLOAD="{\"@type\":\"MessageCard\",\"@context\":\"http://schema.org/extensions\",\"themeColor\":\"${COLOR}\",\"summary\":\"Munin alert\",\"title\":\"Munin alert - ${MUNIN_SERVICESTATE}: ${MUNIN_SERVICE} on ${MUNIN_HOST}\",\"sections\":[{\"activityTitle\":\"[View Munin Console](${MUNIN_CONSOLE})\",\"facts\":[{\"name\":\"Description\",\"value\":\"${MUNIN_SERVICE} execeeds threshold on ${MUNIN_HOST}\"},{\"name\":\"Severity\",\"value\":\"${MUNIN_SERVICESTATE}\"},{\"name\":\"Service\",\"value\":\"${MUNIN_SERVICE}\"},{\"name\":\"Current value\",\"value\":\"${input}\"}],\"markdown\":true}]}" | |
#Send message to Msteams | |
curl -sH 'Content-Type: application/json' -d "${PAYLOAD}" $MSTEAMS_WEBHOOK_URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment