Last active
July 26, 2017 18:53
-
-
Save notpeter/30e62bff6366ea8ef31d to your computer and use it in GitHub Desktop.
Hubot Nagios Integration
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
# Description | |
# A hubot script that notifies of nagios alerts | |
module.exports = (robot) -> | |
robot.router.post '/nagios-alerts', (req, res) -> | |
j = req.body | |
if j.nagioshost | |
msg = "Nagios: #{j.service}@#{j.hostname} #{j.state} #{j.url} " | |
robot.messageRoom '#whatever', msg | |
else | |
console.dir "Nagios POST hook received but not processed." | |
console.dir j | |
res.end 'OK' |
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
############################### | |
# Hubot notifications | |
############################### | |
define command { | |
command_name notify-service-hubot | |
command_line /usr/local/bin/nagios_hubot.sh > /tmp/hubot.log 2>&1 | |
} | |
define command { | |
command_name notify-host-hubot | |
command_line /usr/local/bin/nagios_hubot.sh > /tmp/hubot.log 2>&1 | |
} | |
define contact { | |
contact_name hubot | |
alias Hubot | |
service_notification_period 24x7 | |
host_notification_period 24x7 | |
service_notification_options w,u,c,r | |
host_notification_options d,r | |
service_notification_commands notify-service-hubot | |
host_notification_commands notify-host-hubot | |
} |
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 | |
# nagios_hubot.sh | |
# Posts Nagios alerts via JSON to Hubot (or other web services) | |
# This is based on slack_nagios.sh by Matthew McMillan, modified by Peter Tripp (@notpeter) | |
# http://matthewcmcmillan.blogspot.com/2013/12/simple-way-to-integrate-nagios-with.html | |
#Modify these variables for your environment | |
MY_NAGIOS_HOSTNAME="nagios.whatever.com" | |
MY_NAGIOS_URL="https://${MY_NAGIOS_HOSTNAME}/cgi-bin/nagios3/extinfo.cgi" | |
HUBOT_URL="http://irc.whatever.com:8080/nagios-alerts" | |
AUTH="" | |
#AUTH="--user nagios:basicAUTHpass" | |
# NAGIOS_* environment variables are set by NAGIOS. Full list here: | |
# http://nagios.sourceforge.net/docs/3_0/macrolist.html | |
PAYLOAD="{ \"nagioshost\": \"${MY_NAGIOS_HOSTNAME}\"" | |
PAYLOAD+=", \"hostname\": \"${NAGIOS_HOSTNAME}\"" | |
PAYLOAD+=", \"service\": \"${NAGIOS_SERVICEDESC}\"" | |
PAYLOAD+=", \"state\": \"${NAGIOS_SERVICESTATE}\"" | |
#TODO: sanitize output so it can be passed along. | |
#PAYLOAD+=", \"output\": \"${NAGIOS_LONGSERVICEOUTPUT}\"" | |
PAYLOAD+=", \"url\": \"${MY_NAGIOS_URL}?host=${NAGIOS_HOSTNAME}&service=${NAGIOS_SERVICEDESC}&type=2\"" | |
PAYLOAD+="}" | |
curl $AUTH -X POST -H "Content-Type: application/json" --data "${PAYLOAD}" "${HUBOT_URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment