Last active
October 22, 2016 06:04
-
-
Save arkenous/0ac394d5b76d73041872 to your computer and use it in GitHub Desktop.
Zabbix alertscript for Slack
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
#!/usr/bin/bash | |
# Current time | |
time="$1" | |
# Host name | |
host="$2" | |
# Current trigger value. PROBLEM or OK | |
status="$3" | |
# Numerical trigger severity. 0: Not classified, 1: Information, 2: Warning, 3: Average, 4: High, 5: Disaster | |
nseverity="$4" | |
# Trigger severity name | |
severity="$5" | |
# Name of the trigger | |
name="$6" | |
# Trigger URL | |
url="$7" | |
# Slack channel name to post | |
channel="$8" | |
if [ $status = 'OK' ]; then | |
color='#59DB8F' | |
elif [ $nseverity = '0' ]; then | |
color='#97AAB3' | |
elif [ $nseverity = '1' ]; then | |
color='#7499FF' | |
elif [ $nseverity = '2' ]; then | |
color='#FFC859' | |
elif [ $nseverity = '3' ]; then | |
color='#FFA059' | |
elif [ $nseverity = '4' ]; then | |
color='#E97659' | |
elif [ $nseverity = '5' ]; then | |
color='#E45959' | |
else | |
color='#000000' | |
fi | |
#{ | |
# "channel":"${channel}", | |
# "attachments":[ | |
# { | |
# "fallback":"${status} on ${host} at ${time}", | |
# "pretext":"${status} on ${host} at ${time}", | |
# "color":"${color}", | |
# "fields":[ | |
# { | |
# "title":"[${severity}] ${name}", | |
# "value":"${url}", | |
# "short":false | |
# } | |
# ] | |
# } | |
# ] | |
#} | |
payload="payload={\"channel\":\"${channel}\",\"attachments\":[{\"fallback\":\"${status} on ${host} at ${time}\",\"pretext\":\"${status} on ${host} at ${time}\",\"color\":\"${color}\",\"fields\":[{\"title\":\"[${severity}] ${name}\",\"value\":\"${url}\",\"short\":false}]}]}" | |
curl -m 5 --data-urlencode "${payload}" https://hooks.slack.com/services/YOUR/SLACK/INCOMING/WEBHOOK/URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment