Skip to content

Instantly share code, notes, and snippets.

@iitenkida7
Created March 10, 2023 01:43
Show Gist options
  • Save iitenkida7/77cd808cc355ebdd74c0c7b5f3f6a77a to your computer and use it in GitHub Desktop.
Save iitenkida7/77cd808cc355ebdd74c0c7b5f3f6a77a to your computer and use it in GitHub Desktop.
#!/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