-
-
Save rrichards/fa4ccbb1397d7b395f36cea545ff1aff to your computer and use it in GitHub Desktop.
Simple and stupid, Nagios command for Slack.
This file contains hidden or 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 | |
if [ "$NAGIOS_SERVICESTATE" = "OK" ] | |
then | |
ICON_EMOJI=":thumbsup:" | |
elif [ "$NAGIOS_SERVICESTATE" = "WARNING" ] | |
then | |
ICON_EMOJI=":loundspeaker:" | |
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 | |
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/nagios3/extinfo.cgi?host=${NAGIOS_HOSTNAME}|See Nagios>\"}" ${WEBHOOK_URL} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment