Created
March 10, 2023 01:43
-
-
Save iitenkida7/77cd808cc355ebdd74c0c7b5f3f6a77a to your computer and use it in GitHub Desktop.
This file contains 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 | |
# See: SpecialThanks! => https://colabmix.co.jp/tech-blog/install-zabbix-slack/ | |
SLACK_WEBHOOKSURL='https://hooks.slack.com/services/XXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' | |
SLACK_USERNAME='Zabot' | |
SLACK_ICON=':zabbix:' | |
# "Send to" for Zabbix User Media Setting | |
NOTIFSLACK_Y_CHANNEL="$1" | |
# "Default subject" for Action Operations Setting | |
ALERT_SUBJECT="$2" | |
# "Default message" for Action Operations Setting | |
ALERT_MESSAGE="$3" | |
if [ "${ALERT_SUBJECT%%:*}" == 'OK' ]; then | |
COLOR="good" | |
elif [ "${ALERT_SUBJECT%%:*}" == 'WARNING' ]; then | |
COLOR="warning" | |
elif [ "${ALERT_SUBJECT%%:*}" == 'PROBLEM' ]; then | |
COLOR="danger" | |
else | |
COLOR="#439FE0" | |
fi | |
PAYLOAD="payload={ | |
\"channel\": \"${NOTIFY_CHANNEL//\"/\\\"}\", | |
\"username\": \"${SLACK_USERNAME//\"/\\\"}\", | |
\"icon_emoji\": \"${SLACK_ICON}\", | |
\"attachments\": [ | |
{ | |
\"color\": \"${COLOR}\", | |
\"text\": \"${ALERT_MESSAGE//\"/\\\"}\" | |
} | |
] | |
}" | |
curl -m 5 --data-urlencode "${PAYLOAD}" $SLACK_WEBHOOKSURL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment