Skip to content

Instantly share code, notes, and snippets.

@wilsontayar
Forked from matt448/slack_nagios.sh
Last active August 29, 2015 14:23
Show Gist options
  • Save wilsontayar/3c904eae066ccb7a74d1 to your computer and use it in GitHub Desktop.
Save wilsontayar/3c904eae066ccb7a74d1 to your computer and use it in GitHub Desktop.
#!/bin/bash
MY_NAGIOS_HOSTNAME="http://<insert_nagios_here>"
SLACK_SERVICE_URL="https://hooks.slack.com/services/aaaaaa/aaaaa/aaaaaaa"
if [[ "${NAGIOS_SERVICEOUTPUT}" == *"CRITICAL"* ]]
then
COLOR="danger"
elif [[ "${NAGIOS_SERVICEOUTPUT}" == *"OK"* ]]
then
COLOR="good"
else
COLOR="warning"
fi
MESSAGE="payload={\"attachments\":[{\"fallback\":\"${NAGIOS_HOSTNAME} (${NAGIOS_SERVICEOUTPUT})\",\"color\":\"${COLOR}\",\"title\":\"${NAGIOS_HOSTNAME} (${NAGIOS_SERVICEDISPLAYNAME})\",\"title_link\":\"${MY_NAGIOS_HOSTNAME}/nagios/cgi-bin/extinfo.cgi?type=1&host=${NAGIOS_HOSTNAME}\",\"text\":\"${NAGIOS_SERVICEOUTPUT}\"}]}"
curl -X POST --data-urlencode "${MESSAGE}" ${SLACK_SERVICE_URL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment