Last active
December 21, 2016 16:18
-
-
Save bbuivn/b398832cfcacb6b195b6 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 | |
# This script is used by Shinken to post alerts for hosts into a Slack channel | |
# using the slackcli command line. Create the channel, | |
# and integration first and then add this notification script in your | |
# Shinken configuration. | |
# | |
# You have to set enable_environment_macros=1 in the shinken.cfg configuration file. | |
# | |
# All variables that start with NAGIOS_ are provided by Shinken as | |
# environment variables when a notification is generated. | |
# A list of the env variables is available here: | |
# http://shinken.readthedocs.org/en/latest/05_thebasics/macrolist.html | |
# | |
# More info on Slack | |
# Website: https://slack.com/ | |
# Twitter: @slackhq, @slackapi | |
# | |
# More info on slackcli | |
# Github: https://github.com/candrholdings/slack-cli | |
#Modify these variables for your environment | |
SLACKCLI=$( which slackcli ) | |
SLACK_TOKEN="<your slack token>" | |
SLACK_USER="$( hostname -f )" | |
SLACK_CHANNEL="shinken" | |
BOT_ICON=":shinto_shrine:" | |
#Set the message icon based on Shinken host state | |
if [ "$NAGIOS_HOSTSTATE" = "DOWN" ] | |
then | |
ICON=":red_circle:" | |
elif [ "$NAGIOS_HOSTSTATE" = "UNREACHABLE" ] | |
then | |
ICON=":warning:" | |
elif [ "$NAGIOS_HOSTSTATE" = "UP" ] | |
then | |
ICON=":white_check_mark:" | |
elif [ "$NAGIOS_HOSTSTATE" = "UNKNOWN" ] | |
then | |
ICON=":question:" | |
else | |
ICON=":white_medium_square:" | |
fi | |
#Send message to Slack | |
"${SLACKCLI}" -t "${SLACK_TOKEN}" -u "${SLACK_USER}" -h "${SLACK_CHANNEL}" -e "${BOT_ICON}" -m "${ICON} Type: ${NAGIOS_NOTIFICATIONTYPE} | |
${ICON} Host: ${NAGIOS_HOSTNAME} | |
${ICON} State: ${NAGIOS_HOSTSTATE} | |
${ICON} Infos: ${NAGIOS_HOSTOUTPUT} | |
${ICON} Date: ${NAGIOS_LONGDATETIME}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment