+ All Categories
Home > Technology > An introduction to Hubot - CloudConf 2015 - Turin Italy

An introduction to Hubot - CloudConf 2015 - Turin Italy

Date post: 15-Jul-2015
Category:
Upload: corley-srl
View: 272 times
Download: 1 times
Share this document with a friend
29
Automation with Hubot! Chat with a friend every day...
Transcript

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

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

Hubot

Centralize actions in a singleplace

Centralize all information in asingle place

Share all information with theright people

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

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

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

Attach your scripts "hubot-scripts.json"

[  "test"]

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

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

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

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

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

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

responding

hearing

But we can get moreinteresting stuff from our

ecosystem and hubot!

Notifications flow on scalingactivities

We can read any data from ourmonitors and send them into

the chat roomReact to Alarms

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

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'

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.

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

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

Using eventsHubot encapsulate the EventEmitter from NodeJS.

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'    }

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

Hubot as a lot of interestingfeatures

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

Thanks forlistening


Recommended