Top Banner
Automation with Hubot! Chat with a friend every day...
29

An introduction to Hubot - CloudConf 2015 - Turin Italy

Jul 15, 2015

Download

Technology

Corley S.r.l.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An introduction to Hubot - CloudConf 2015 - Turin Italy

Automation with Hubot!Chat with a friend every day...

Page 2: An introduction to Hubot - CloudConf 2015 - Turin Italy

About meCofounder @CorleyCloud - www.corley.itCofounder @UpCloo LTD

Page 3: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hubot

Page 4: An introduction to Hubot - CloudConf 2015 - Turin Italy

Centralize actions in a singleplace

Page 5: An introduction to Hubot - CloudConf 2015 - Turin Italy

Centralize all information in asingle place

Page 6: An introduction to Hubot - CloudConf 2015 - Turin Italy

Share all information with theright people

Page 7: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hubot is simplenpm install -g generator-hubotyo hubotCoffeescript or JavaScript for coding

Page 8: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hubot compositionAdapter -> which chat to useBrain -> Store short and long term informationListen and Reacts -> partecipate to discussions

Page 9: An introduction to Hubot - CloudConf 2015 - Turin Italy

How it is composed15:04 $ ls ­ltotal 36drwxrwxr­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.jsondrwxrwxr­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.mddrwxrwxr­x  2 walter walter 4096 mar 15 20:31 scripts

Page 10: An introduction to Hubot - CloudConf 2015 - Turin Italy

Attach your scripts "hubot-scripts.json"

[  "test"]

It is related to a "scripts/test.coffee" file

Page 11: An introduction to Hubot - CloudConf 2015 - Turin Italy

The anatomy of a scriptmodule.exports = (robot) ­>  # your code here

Page 12: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hearing/Sendwdalmut: guys, do we have problems in production?hubot: http://somewhere.tld/cpu/average.png

Page 13: An introduction to Hubot - CloudConf 2015 - Turin Italy

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

Page 14: An introduction to Hubot - CloudConf 2015 - Turin Italy

Responing/Replywdalmut: hey @hubot can you draw the actual load status?hubot: http://somewhere.tld/cpu/average.png

Page 15: An introduction to Hubot - CloudConf 2015 - Turin Italy

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

Page 16: An introduction to Hubot - CloudConf 2015 - Turin Italy

responding

Page 17: An introduction to Hubot - CloudConf 2015 - Turin Italy

hearing

Page 18: An introduction to Hubot - CloudConf 2015 - Turin Italy

But we can get moreinteresting stuff from our

ecosystem and hubot!

Page 19: An introduction to Hubot - CloudConf 2015 - Turin Italy

Notifications flow on scalingactivities

Page 20: An introduction to Hubot - CloudConf 2015 - Turin Italy

We can read any data from ourmonitors and send them into

the chat roomReact to Alarms

AWS CloudWatch Alarms => AWS SNS (HTTP) => Chat room

Page 21: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hubot can react on HTTP callsCapture 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'

Page 22: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hubot can make HTTP requestsThanks to Scoped-HTTP-Client you can make any HTTP requestrobot.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 ajQuery like selectors and we interact directly with web pages.

Page 23: An introduction to Hubot - CloudConf 2015 - Turin Italy

Do not put your secret keysinto scripts

you can pass variables to your hubot using environment variablesaws_key = process.env.HUBOT_AWS_KEYaws_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

Page 24: An introduction to Hubot - CloudConf 2015 - Turin Italy

Say hello and goodbye to ourteam mates

module.exports = (robot) ­>

  robot.enter (msg) ­>    msg.send "Welcome!!!!"

  robot.leave (msg) ­>    msg.send "Have a nice day!!"

Enter/Leave messages

Page 25: An introduction to Hubot - CloudConf 2015 - Turin Italy

Using eventsHubot encapsulate the EventEmitter from NodeJS.

Page 26: An introduction to Hubot - CloudConf 2015 - Turin Italy

On commit notifies thatsomething happens

# src/scripts/github­commits.coffeemodule.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'    }

Page 27: An introduction to Hubot - CloudConf 2015 - Turin Italy

Other scripts can receiveevents

# src/scripts/heroku.coffeemodule.exports = (robot) ­>  robot.on "commit", (commit) ­>    robot.send commit.user, "Will now deploy #{commit.hash} from #{commit.repo}!"    #deploy code goes here

Page 28: An introduction to Hubot - CloudConf 2015 - Turin Italy

Hubot as a lot of interestingfeatures

Discover more feature on https://hubot.github.com/docs

Page 29: An introduction to Hubot - CloudConf 2015 - Turin Italy

Thanks forlistening