Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

An introduction to Hubot - CloudConf 2015 - Turin Italy

1,115 views

Published on

An introduction to Hubot - CloudConf 2015 Turin Italy

Published in: Technology
  • Be the first to comment

An introduction to Hubot - CloudConf 2015 - Turin Italy

  1. 1. Automation with Hubot! Chat with a friend every day...
  2. 2. About me Cofounder @CorleyCloud - www.corley.it Cofounder @UpCloo LTD
  3. 3. Hubot
  4. 4. Centralize actions in a single place
  5. 5. Centralize all information in a single place
  6. 6. Share all information with the right people
  7. 7. Hubot is simple npm install -g generator-hubot yo hubot Coffeescript or JavaScript for coding
  8. 8. Hubot composition Adapter -> which chat to use Brain -> Store short and long term information Listen and Reacts -> partecipate to discussions
  9. 9. How it is composed 15:04 $ ls ­l total 36 drwxrwxr­x  2 walter walter 4096 mar 15 17:47 bin ­rw­rw­r­­  1 walter walter  232 mar 15 17:47 external­scripts.json ­rw­rw­r­­  1 walter walter   13 mar 15 18:05 hubot­scripts.json drwxrwxr­x 17 walter walter 4096 mar 15 17:49 node_modules ­rw­r­­r­­  1 walter walter  695 mar 15 17:49 package.json ­rw­r­­r­­  1 walter walter   26 mar 15 17:48 Procfile ­rw­r­­r­­  1 walter walter 7820 mar 15 17:47 README.md drwxrwxr­x  2 walter walter 4096 mar 15 20:31 scripts
  10. 10. Attach your scripts "hubot- scripts.json" [   "test" ] It is related to a "scripts/test.coffee" file
  11. 11. The anatomy of a script module.exports = (robot) ­>   # your code here
  12. 12. Hearing/Send wdalmut: guys, do we have problems in production? hubot: http://somewhere.tld/cpu/average.png
  13. 13. Hearing/Send (hubot side) robot.hear /regular­expression/i, (msg) ­>   # get the actual status and send it   msg.send "the image url" # the chat will append the real image
  14. 14. Responing/Reply wdalmut: hey @hubot can you draw the actual load status? hubot: http://somewhere.tld/cpu/average.png
  15. 15. Responing/Reply (hubot side) robot.respond /regular­expression/i, (msg) ­>   # get the actual status and send it   msg.reply "the image url" # the chat will append the real image
  16. 16. responding
  17. 17. hearing
  18. 18. But we can get more interesting stuff from our ecosystem and hubot!
  19. 19. Notifications flow on scaling activities
  20. 20. We can read any data from our monitors and send them into the chat room React to Alarms AWS CloudWatch Alarms => AWS SNS (HTTP) => Chat room
  21. 21. Hubot can react on HTTP calls Capture events outside chat rooms module.exports = (robot) ­>   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'
  22. 22. Hubot can make HTTP requests Thanks to Scoped-HTTP-Client you can make any HTTP request robot.http("https://my­rest­endpoint.tld/resource").get() (err, res, body) ­>       # your code here For screen-scraping sessions you can use "cheerio" that it has a jQuery like selectors and we interact directly with web pages.
  23. 23. Do not put your secret keys into scripts you can pass variables to your hubot using environment variables aws_key = process.env.HUBOT_AWS_KEY aws_secret = process.env.HUBOT_AWS_SECRET module.exports = (robot) ­>   robot.respond /add (+d) server(s)?/i, (msg) ­>     # use aws_key and aws_secret in order to add more resources to your cluster
  24. 24. Say hello and goodbye to our team mates module.exports = (robot) ­>   robot.enter (msg) ­>     msg.send "Welcome!!!!"   robot.leave (msg) ­>     msg.send "Have a nice day!!" Enter/Leave messages
  25. 25. Using events Hubot encapsulate the EventEmitter from NodeJS.
  26. 26. On commit notifies that something happens # src/scripts/github­commits.coffee module.exports = (robot) ­>   robot.router.post "/hubot/gh­commits", (req, res) ­>     robot.emit "commit", {         user    : {}, #hubot user object         repo    : 'https://github.com/github/hubot',         hash  : '2e1951c089bd865839328592ff673d2f08153643'     }
  27. 27. Other scripts can receive events # src/scripts/heroku.coffee module.exports = (robot) ­>   robot.on "commit", (commit) ­>     robot.send commit.user, "Will now deploy #{commit.hash} from #{commit.repo}!"     #deploy code goes here
  28. 28. Hubot as a lot of interesting features Discover more feature on https://hubot.github.com/docs
  29. 29. Thanks for listening

×