##什么是chatops ChatOps是诞生于GitHub的一种基于会话驱动的协作开发方法,过去团队之间的通讯和开发操作是两层皮,导致各种不透明和低效率。ChatOps将开发工具带入开发者聊天室,通过定制的插件和脚本,一个聊天机器人能够执行聊天中输入的各种命令,实现在聊天平台上的团队协作开发自动化,把团队沟通和执行统一整合到一个可视化更高的聊天环境中,“聊着天就把事情办了”。
##StackStorm安装 参考: StackStorm安装与配置
##hubot安装 ###安装最新版nodejs与npm
cd /usr/local/src
wget https://nodejs.org/dist/v0.12.7/node-v0.12.7-linux-x64.tar.gz
tar -xf node-v0.12.7-linux-x64.tar.gz
mv node-v0.12.7-linux-x64 /usr/local
ln -s /usr/local/node-v0.12.7-linux-x64/bin/node /usr/local/bin/node
ln -s /usr/local/node-v0.12.7-linux-x64/bin/npm /usr/local/bin/npm
###安装hubot
npm install -g yo generator-hubot
###创建自己的聊天机器人
mkdir /opt/myhubot
cd /opt/myhubot
yo hubot
###使用git进行版本控制(可选)
git init
git add .
git commit -m "Initial commit"
###启动机器人 hubot默认监听8080端口,与stackstorm冲突,设置PORT
环境变量修改hubot默认端口
# PORT=8181 bin/hubot
myhubot>
####测试
myhubot help
hubot adapter - Reply with the adapter
hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
hubot echo <text> - Reply back with <text>
hubot help - Displays all of the help commands that hubot knows about.
hubot help <query> - Displays all help commands that match <query>.
hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
hubot map me <query> - Returns a map view of the area returned by `query`.
hubot mustache me <query> - Searches Google Images for the specified query and mustaches it.
hubot mustache me <url> - Adds a mustache to the specified URL.
hubot ping - Reply with pong
hubot pronounce <phrase> in <language> - Provides pronounciation of <phrase> (<language> is optional)
hubot pug bomb N - get N pugs
hubot pug me - Receive a pug
hubot the rules - Make sure hubot still knows the rules.
hubot time - Reply with current time
hubot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
hubot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
hubot youtube me <query> - Searches YouTube for the query and returns the video embed link.
ship it - Display a motivation squirrel
##安装StackStorm Hubot plugin 安装hubot-stackstorm:
cd /opt/myhubot
npm install hubot-stackstorm
编辑external-scripts.json
[
...
"hubot-stackstorm"
]
最终看起来应该像这样:
[
"hubot-diagnostics",
"hubot-help",
"hubot-heroku-keepalive",
"hubot-google-images",
"hubot-google-translate",
"hubot-pugme",
"hubot-maps",
"hubot-redis-brain",
"hubot-rules",
"hubot-shipit",
"hubot-youtube",
"hubot-stackstorm"
]
设置环境变量
ST2_API
- StackStorm Api地址.ST2_WEBUI_URL
- StackStorm web地址(可选)。ST2_CHANNEL
- 聊天频道
启动hubot
PORT=8181 ST2_CHANNEL="#general" ST2_API="http://127.0.0.1:9101" ST2_WEBUI_URL="http://127.0.0.1:8080" bin/hubot --alias !
##配置StackStorm 安装hubot
包到StackStorm:
st2 run packs.install packs=hubot,st2
修改默认频道:
#vim /opt/stackstorm/packs/hubot/rules/notify_hubot.yaml
...
criteria:
trigger.channel:
pattern: "#general"
type: "equals"
...
##使配置生效
st2ctl reload --register-all
st2ctl restart
重新打开hubot:
# PORT=8181 ST2_CHANNEL="#general" ST2_API="http://127.0.0.1:9101" ST2_WEBUI_URL="http://127.0.0.1:8080" bin/hubot --alias !
myhubot> myhubot st2 list actions
myhubot> Want me to take that off your hand? You got it! Don't forget your execution ID: 55b74a6c636239237f07916d (details available at http://172.18.11.106:8080/#/history/55b74a6c636239237f07916d/general)
Shell :
Action st2.actions.list completed.
status : succeeded
execution: 55b74a6c636239237f07916d
result :
--------
result : [{u'description': u'Action that performs an http request.', u'runner_type': u'http-request', u'tags': [], u'enabled': True, u'name': u'http', u'entry_point': u'', u'ref': u'core.http', u'id': u'55b0f8676362395abc0c77ef', u'pack': u'core'}, {u'description': u'Action that executes an arbitrary Linux command on the localhost.', u'runner_type': u'local-shell-cmd', u'tags': [], u'enab...
Execution details available at: http://172.18.11.106:8080/#/history/55b74a6c636239237f07916d/general
myhubot>
##参考 st2/instructables/chatops.md