Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Chatops with Hubot

Chatops with Hubot

This talk was given at Velocity Amsterdam 2015

Lorna Mitchell

October 30, 2015
Tweet

More Decks by Lorna Mitchell

Other Decks in Technology

Transcript

  1. ChatOps with Hubot
    Lorna Mitchell, October 2015

    View full-size slide

  2. Think of DevOps

    View full-size slide

  3. This is ChatOps

    View full-size slide

  4. ChatOps
    Puts the "S" in CAMS
    A Culture of Automation, Measurement and Sharing

    View full-size slide

  5. ChatOps
    Brings the automation into the conversation.
    Team is in channel; information needs to be there too

    View full-size slide

  6. Choose Your Bot
    • Lita (ruby) https://www.lita.io/
    • Err (python) http://errbot.net/
    • Hubot (coffeescript) https://hubot.github.com/

    View full-size slide

  7. Hubot
    "Friendly chat robot from GitHub"
    • Shared plugins
    • Good community

    View full-size slide

  8. Supported Channels
    • Slack
    • Campfire
    • Hipchat
    • IRC
    • Shell
    • ... pluggable adapters

    View full-size slide

  9. Installation
    Very easy install via yeoman:
    https://hubot.github.com/docs/
    Bonus blog post: http://lrnja.net/1KugmaC
    Then: ./bin/hubot

    View full-size slide

  10. Meet Hugh
    Hugh is a hubot.
    Here, I'm running:
    • IRC server: miniircd
    https://github.com/jrosdahl/miniircd
    • IRC client: irssi http://irssi.org/

    View full-size slide

  11. Simply Deployable
    Designed to run on Heroku, easy to run elsewhere
    • Get Heroku toolchain
    • heroku create
    • Set environment variables
    • Configure Procfile
    • git push heroku master

    View full-size slide

  12. Many Plugins
    Search for "hubot [thing]" on https://www.npmjs.com/
    Install and add to list in external-scripts.json
    Or add your own code to scripts/

    View full-size slide

  13. Plugins
    Very easy scripting, make a scripts/*.coffee file and
    export a function:
    module.exports = (robot) ->
    # your code here

    View full-size slide

  14. Plugins
    Simple plugin: use cron to do a timed feature
    Also: happy hour, standup meetings

    View full-size slide

  15. Plugin Code
    ROOM = process.env.HUBOT_TIMESHEET_REMINDER_ROOM
    cronJob = require('cron').CronJob
    module.exports = (robot) ->
    doReminder = ->
    robot.messageRoom(ROOM, "This is a polite reminder.
    Fill in your timesheets for the week, please");
    job = new cronJob("0 0 17 * * 5", doReminder, null, true)
    https://github.com/lornajane/hubot-timesheet-reminder

    View full-size slide

  16. Managing Plugins

    View full-size slide

  17. robot.respond
    rules = [
    "1. A robot may not injure a human being or, through inaction, allow a hu
    "2. A robot must obey any orders given to it by human beings, except wher
    "3. A robot must protect its own existence as long as such protection doe
    ]
    module.exports = (robot) ->
    robot.respond /(what are )?the (three |3 )?(rules|laws)/i, (msg) ->
    text = msg.message.text
    msg.send rules.join('\n')

    View full-size slide

  18. robot.hear
    quotes = [
    "Life! Don't talk to me about life",
    "Life, loathe it or ignore it, you can't like it",
    "Life's bad enough as it is without wanting to invent any more of it",
    "Funny, how just when you think life can't possibly get any worse it sudd
    ]
    module.exports = (robot) ->
    robot.hear /(.*)(life)(.*)/i, (msg) ->
    msg.send msg.random quotes

    View full-size slide

  19. Webhooks
    Collate events from all tools into your chat rooms
    Alerts from:
    • monitoring/logs
    • commits
    • issues/pull requests
    • deploys

    View full-size slide

  20. Webhooks In Practice

    View full-size slide

  21. Webhooks In Practice

    View full-size slide

  22. Webhooks In Practice

    View full-size slide

  23. Webhooks In Practice

    View full-size slide

  24. Developing for Webhooks
    To test webhooks on a dev platform, try ngrok
    (https://ngrok.com/)
    Secure tunnel to a port on your machine, with:
    • ability to inspect traffic
    • option to replay (rather than having to retrigger)

    View full-size slide

  25. API Calls
    Command your bot

    View full-size slide

  26. Team Relations
    • Thanks plugin
    • Karma
    • Ship It
    • The Rules

    View full-size slide

  27. ChatOps in Teams
    Unsolicited advice from me:
    • Works for open source and commercial teams
    • Build on existing plugins
    • Don't take it too seriously

    View full-size slide

  28. ChatOps in Teams
    Unsolicited advice from me:
    • Works for open source and commercial teams
    • Build on existing plugins
    • Don't take it too seriously
    • Never ask permission

    View full-size slide