© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
ChatOps
Les humains parlent aux robots
Olivier Jacques / @ojacques2 / #devops #meetup
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.2
Pour vous servir…
Olivier Jacques – HP Grenoble
• Distinguished Technologist / HP IT - DevOps
@ojacques2
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.3
Des salles de Chat et des Bots
ChatOps
• Dev: plus d’Ops. Ops: plus de Dev.• Conversations entre robots et humains• Archives, recherches, audit• Les robots publient des événements, répondent à
des questions• Une base de connaissance commune dans
l’équipe DevOps• C’est drôle !• Nous, on aime http://flowdock.com
– Il y a aussi IRC, Hipchat, campfire, …• Un bot populaire: HUBOT -
https://hubot.github.com/
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.4
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.
Travaux Pratiques
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.6
Travaux pratiques
1
2
3
Créer son bot
Le connecter à IRC
Créer deux scripts: ligne de commande, webhook
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.7
Sur un Ubuntu 14.04 LTS
Installer Hubot
$ curl -sL https://deb.nodesource.com/setup | sudo bash -
$ sudo apt-get install nodejs build-essential libexpat1-dev libexpat1 libicu-dev
$ sudo npm install npm –g
$ npm install -g yo generator-Hubot
$ mkdir mytestbot
$ cd mytestbot
$ yo hubot
OU…
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.8
start.sh
#!/bin/bash#
HUBOT_HOME_DIR=/home/ubuntu/testbot/HUBOT_BIN='bin/hubot'HUBOT_LOGS_DIR=~/logs
cd ${HUBOT_HOME_DIR}mkdir -p ${HUBOT_LOGS_DIR}
if [ ! -f ./hubot.env ]; then echo "hubot.env file not found!" exit 1fi
source ./hubot.env
${HUBOT_HOME_DIR}${HUBOT_BIN} --name ${HUBOT_NAME} --adapter ${ADAPTER}
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.9
hubot.env
export HUBOT_LOG_LEVEL=debugexport PORT=‘8080' # http listeners for web hooksexport HUBOT='bin/hubot'export ADAPTER='irc'export HUBOT_IRC_ROOMS='#meetup-devops-gre'export HUBOT_IRC_SERVER='irc.freenode.net'export HUBOT_NAME='Nono1981' # what hubot listens to
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.10
cal.coffee
# Commands:# hubot calendar <month>: prints out a calendar
child_process = require 'child_process'
module.exports = (robot) -> robot.respond /calendar (.*)/i, (msg) -> month = msg.match[1] if month child_process.exec 'cal -h -m ' + month, (error, stdout, stderr) -> msg.send(stdout) msg.send(stderr)
© Copyright 2015 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.11
+ Webhook
cal.coffee
# Commands:# hubot calendar <month>: prints out a calendar
child_process = require 'child_process'
module.exports = (robot) -> robot.respond /calendar (.*)/i, (msg) -> month = msg.match[1] if month child_process.exec 'cal -h -m ' + month, (error, stdout, stderr) -> msg.send(stdout) msg.send(stderr)
robot.router.get "/hubot/test", (req, res) -> res.end "Thanks!" robot.messageRoom "#meetup-devops-gre", "Got a request..."