Skip to content

Instantly share code, notes, and snippets.

@jasonthomas
Last active December 11, 2015 07:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonthomas/4568942 to your computer and use it in GitHub Desktop.
Save jasonthomas/4568942 to your computer and use it in GitHub Desktop.
AWS SNS script for hubot
# Description:
# This script receives messages from AWS SNS topic for cloudwatch
#
# Author:
# jasonthomas
irc = require('irc')
SNSClient = require('aws-snsclient')
module.exports = (robot) ->
robot.router.post '/hubot/sns/:room', (req, res) ->
room = req.params.room
auth =
verify: false
client = SNSClient(auth, (err, message) ->
throw err if err
if message.Subject.match /OK/
state_color = 'light_green'
else if message.Subject.match /ALARM/
state_color = 'light_red'
else
state_color = 'orange'
state = irc.colors.wrap(state_color, message.Subject)
reason = irc.colors.wrap('white', JSON.parse(message.Message).NewStateReason)
robot.messageRoom "##{room}", "#{state}: #{reason}"
)
client(req, res)
res.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment