Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
work in progress on a consul hubot script
# Description:
# Query Consul with Hubot
#
# Commands:
# hubot consul datacenters - Show Datacenters
# hubot consul services - Show Services
# hubot consul service <servicename> - Show Detailed info about a service
#
# Notes:
# They are commented out by default, because most of them are pretty silly and
# wouldn't be useful and amusing enough for day to day huboting.
# Uncomment the ones you want to try and experiment with.
#
# These are from the scripting documentation: https://github.com/github/hubot/blob/master/docs/scripting.md
module.exports = (robot) ->
# Datacenters
robot.hear /consul datacenters/i, (msg) ->
msg.http("http://consul.verticacorp.com:8500/v1/catalog/datacenters").get() (err, res, body) ->
try
json = JSON.parse(body)
for dc in json
msg.send "#{dc}\n"
catch error
msg.reply "I'm afraid I can't let you do that."
# Services
robot.hear /consul services/i, (msg) ->
msg.http("http://consul.verticacorp.com:8500/v1/catalog/services").get() (err, res, body) ->
try
#msg.send "#{body}\n"
json = JSON.parse(body)
for key, val of json
msg.send "#{key}\n"
#msg.send "#{json}\n"
catch error
msg.reply "I'm afraid I can't let you do that."
# Detailed Info about services
robot.hear /consul service (.*)/i, (msg) ->
service = escape(msg.match[1])
msg.http("http://consul.verticacorp.com:8500/v1/catalog/service/#{service}").get() (err, res, body) ->
try
#msg.send "#{body}\n"
json = JSON.parse(body)
for item in json
for k, v of item
msg.send "#{k} : #{v}"
catch error
msg.reply "I'm afraid I can't let you do that."
# msg.send "Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS"
# robot.hear /badger/i, (msg) ->
# msg.send "Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS"
#
# robot.respond /open the (.*) doors/i, (msg) ->
# doorType = msg.match[1]
# if doorType is "pod bay"
# msg.reply "I'm afraid I can't let you do that."
# else
# msg.reply "Opening #{doorType} doors"
#
# robot.hear /I like pie/i, (msg) ->
# msg.emote "makes a freshly baked pie"
#
# lulz = ['lol', 'rofl', 'lmao']
#
# robot.respond /lulz/i, (msg) ->
# msg.send msg.random lulz
#
# robot.topic (msg) ->
# msg.send "#{msg.message.text}? That's a Paddlin'"
#
#
# enterReplies = ['Hi', 'Target Acquired', 'Firing', 'Hello friend.', 'Gotcha', 'I see you']
# leaveReplies = ['Are you still there?', 'Target lost', 'Searching']
#
# robot.enter (msg) ->
# msg.send msg.random enterReplies
# robot.leave (msg) ->
# msg.send msg.random leaveReplies
#
# answer = process.env.HUBOT_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING
#
# robot.respond /what is the answer to the ultimate question of life/, (msg) ->
# unless answer?
# msg.send "Missing HUBOT_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING in environment: please set and try again"
# return
# msg.send "#{answer}, but what is the question?"
#
# robot.respond /you are a little slow/, (msg) ->
# setTimeout () ->
# msg.send "Who you calling 'slow'?"
# , 60 * 1000
#
# annoyIntervalId = null
#
# robot.respond /annoy me/, (msg) ->
# if annoyIntervalId
# msg.send "AAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIHHHHHHHHHH"
# return
#
# msg.send "Hey, want to hear the most annoying sound in the world?"
# annoyIntervalId = setInterval () ->
# msg.send "AAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIHHHHHHHHHH"
# , 1000
#
# robot.respond /unannoy me/, (msg) ->
# if annoyIntervalId
# msg.send "GUYS, GUYS, GUYS!"
# clearInterval(annoyIntervalId)
# annoyIntervalId = null
# else
# msg.send "Not annoying you right now, am I?"
#
#
# robot.router.post '/hubot/chatsecrets/:room', (req, res) ->
# room = req.params.room
# data = JSON.parse req.body.payload
# secret = data.secret
#
# robot.messageRoom room, "I have a secret: #{secret}"
#
# res.send 'OK'
#
# robot.error (err, msg) ->
# robot.logger.error "DOES NOT COMPUTE"
#
# if msg?
# msg.reply "DOES NOT COMPUTE"
#
# robot.respond /have a soda/i, (msg) ->
# # Get number of sodas had (coerced to a number).
# sodasHad = robot.brain.get('totalSodas') * 1 or 0
#
# if sodasHad > 4
# msg.reply "I'm too fizzy.."
#
# else
# msg.reply 'Sure!'
#
# robot.brain.set 'totalSodas', sodasHad+1
#
# robot.respond /sleep it off/i, (msg) ->
# robot.brain.set 'totalSodas', 0
# robot.respond 'zzzzz'
@msabramo

This comment has been minimized.

Copy link

commented Oct 14, 2015

I wonder if you've done any further work on this?

(Before I grab this and start doing some hacking of my own...)

Thanks for sharing!!

@ChristianKniep

This comment has been minimized.

Copy link

commented Nov 6, 2015

I am interested as well... :)

@tfhartmann

This comment has been minimized.

Copy link
Owner Author

commented Dec 4, 2015

Oh yikes sorry guys! I didn't see the comments, I hadn't but would love to work with you on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.