Last active
December 11, 2015 07:48
-
-
Save jasonthomas/4568942 to your computer and use it in GitHub Desktop.
AWS SNS script for 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
# 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