StackStorm与ChatOps

##什么是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

StackStorm Hubot Plugin

Hubot Documentation

转载于:https://my.oschina.net/fmnisme/blog/592772

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值