-
-
Save otsuarez/efaa97fa91885248caab 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 | |
WEBHOST_NAGIOS="<Host that nagios is runing on>" | |
SLACK_CHANNEL="#<Channel name>" | |
SLACK_BOTNAME="<Bot Name>" | |
WEBHOOK_URL="<Webhook URL>" #Get it from Slack Incoming WebHooks setup instruction | |
#Set the message icon based on Nagios service state | |
# supported emoji table available at http://unicodey.com/emoji-data/table.htm | |
if [ "$NAGIOS_SERVICESTATE" = "OK" ] | |
then | |
ICON_EMOJI=":thumbsup:" | |
elif [ "$NAGIOS_SERVICESTATE" = "WARNING" ] | |
then | |
ICON_EMOJI=":loudspeaker:" | |
elif [ "$NAGIOS_SERVICESTATE" = "CRITICAL" ] | |
then | |
ICON_EMOJI=":broken_heart:" | |
elif [ "$NAGIOS_SERVICESTATE" = "UNKNOWN" ] | |
then | |
ICON_EMOJI=":troll:" | |
else | |
ICON_EMOJI=":octocat:" | |
fi | |
#request for posting to a channel | |
#in json & should be encoded as %26 | |
curl -X POST --data "payload={\"channel\": \"${SLACK_CHANNEL}\", \"username\": \"${SLACK_BOTNAME}\", \"icon_emoji\": \":vertical_traffic_light:\", \"text\": \"${ICON_EMOJI} HOST: ${NAGIOS_HOSTNAME} SERVICE: ${NAGIOS_SERVICEDISPLAYNAME} STATE: ${NAGIOS_SERVICESTATE} MESSAGE: ${NAGIOS_SERVICEOUTPUT} <http://${WEBHOST_NAGIOS}/cgi-bin/extinfo.cgi?type=1%26host=${NAGIOS_HOSTNAME}|See Nagios>\"}" ${WEBHOOK_URL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment