Skip to content

Instantly share code, notes, and snippets.

@maethor
Created October 3, 2013 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maethor/6807422 to your computer and use it in GitHub Desktop.
Save maethor/6807422 to your computer and use it in GitHub Desktop.
Nagios and Shinken hubot script
# Description:
# This script receives pages in the formats
# /usr/bin/curl -d host="$HOSTALIAS$" -d output="$SERVICEOUTPUT$" -d description="$SERVICEDESC$" -d type=service -d state="$SERVICESTATE$" $CONTACTADDRESS1$
# /usr/bin/curl -d host="$HOSTNAME$" -d output="$HOSTOUTPUT$" -d type=host -d state="$HOSTSTATE$" $CONTACTADDRESS1$
#
# Author:
# maethor
# based on oremj (https://gist.github.com/oremj/3702073)
irc = require('irc')
module.exports = (robot) ->
bold = (text) ->
"\x02" + text + "\u000f"
underline = (text) ->
"\x1f" + text + "\u000f"
room = process.env.NAGIOS_CHANNEL
robot.router.post '/nagios', (req, res) ->
host = irc.colors.wrap('orange', req.body.host)
output = irc.colors.wrap('white', req.body.output)
state = req.body.state
if state == 'OK' or state == 'UP'
state_color = 'light_green'
else if state == 'CRITICAL' or state == 'DOWN'
state_color = 'light_red'
else if state == 'WARNING'
state_color = 'yellow'
else
state_color = 'orange'
state = irc.colors.wrap(state_color, state)
if req.body.type == 'host'
robot.messageRoom "#{room}", "shinken: #{host} is #{bold(state)}: #{output}"
else
service = req.body.description
robot.messageRoom "#{room}", "shinken: #{host}:#{service} is #{bold(state)}: #{output}"
res.writeHead 204, { 'Content-Length': 0 }
res.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment