Skip to content

Instantly share code, notes, and snippets.

@ronaldevers
Forked from oremj/nagios.coffee
Last active December 16, 2015 18:29
Show Gist options
  • Save ronaldevers/5478410 to your computer and use it in GitHub Desktop.
Save ronaldevers/5478410 to your computer and use it in GitHub Desktop.
Hubot script to receive notifications from Nagios. Refactored using switch and better flow and uses a little less color compared to the original gist.
# 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:
# oremj
# ronaldevers
irc = require('irc')
module.exports = (robot) ->
robot.router.post '/hubot/nagios/:room', (req, res) ->
room = req.params.room
host = req.body.host
output = req.body.output
if req.body.type == 'host'
robot.messageRoom "##{room}", "nagios: #{host} is #{output}"
else
state_color = switch req.body.state
when 'OK' then 'light_green'
when 'CRITICAL' then 'light_red'
when 'WARNING' then 'yellow'
else 'orange'
state = irc.colors.wrap(state_color, req.body.state)
service = req.body.description
robot.messageRoom "##{room}", "nagios: #{host}:#{service} is #{state}: #{output}"
res.writeHead 204
res.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment