ChatOps工具之Hubot
2017-05-30 19:15
232 查看
Hubot简介
Hubot的最初的一个版本是用于作为Github的chat room, 当然不只是一个聊天机器人,使用Hubot可以用于自动化集成,实施部署,搞点乐子等等,在Github他们就是这样做的,Hubot被称为Github最忙碌的员工。而后又使用Coffeescript对项目进行了重写,在Github上也受到了广泛的好评。使用场景
使用Hubot可以用于很多场景,其中很多都已经是在被实践之中了预定内部会议室
通知代办事项
更新系统补丁
检查系统状态
部署应用程序
…
当然这些需要自己写脚本或者模块来实现,而这些根DevOps的实践也非常的相近。其实Hubot聊天机器人作为ChatOps的一个实现,除了Hubot之外还有收费的hipchat等,而ChatOps本身也是受DevOps的触动而产生的一个概念。当然除了这些正经的场景还有一些其他的场景诸如:
咨询附近的美食
工作累了让Hubot讲个笑话
问Hubot自己长得是不是很帅
…
不要妄图去断定我们程序员都是怎么想的,你猜来猜去也猜不明白。我只能说,这些也非常之重要,虽然很无聊,人生不就是图一乐和麽。
ChatOps工具
除了Hubot,ChatOps常用的工具还有诸如Slack
HipChat
Gitter
等等,在此不再一一列举。
依赖
前面已经提到现在的Hubot已经是使用CoffeeScript改写过的,所以自然其运行环境的依赖如下项番 | 依赖组件 |
---|---|
No.1 | Node.js |
No.2 | Npm |
支持的平台
Hubot缺省支持Heroku,但并非仅限于此,目前Hubot支持部署的平台如下Windows
Unix
Heroku
Azure
BlueMix
其他依赖
除了Node.js和Npm以外,由于Hubot使用Redis报存其持久层数据,所以Redis也是需要安装的,但是仅仅是体验功能的话,Redis不安装也可以。安装Node & Npm
安装地址如下,项目 | 详细信息 |
---|---|
地址 | https://nodejs.org/en/download/ |
下载地址 | https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz |
Nodejs版本 | 6.10.3 |
Npm版本 | 3.10.10 |
安装命令
mkdir -p /usr/local/nodejs cd /usr/local/nodejs wget https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz tar node-v6.10.3-linux-x64.tar.xz
安装日志
[root@liumiaocn ~]# mkdir -p /usr/local/nodejs [root@liumiaocn ~]# cd /usr/local/nodejs [root@liumiaocn nodejs]# wget https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz --2017-05-30 04:58:11-- https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz Resolving nodejs.org (nodejs.org)... 104.20.22.46, 104.20.23.46, 2400:cb00:2048:1::6814:162e, ... Connecting to nodejs.org (nodejs.org)|104.20.22.46|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 9366220 (8.9M) [application/x-xz] Saving to: ‘node-v6.10.3-linux-x64.tar.xz’ 100%[=========================================================================================================>] 9,366,220 278KB/s in 35s 2017-05-30 04:58:48 (258 KB/s) - ‘node-v6.10.3-linux-x64.tar.xz’ saved [9366220/9366220] [root@liumiaocn nodejs]#tar xvpf node-v6.10.3-linux-x64.tar.xz ... node-v6.10.3-linux-x64/lib/node_modules/npm/node_modules/umask/index.js node-v6.10.3-linux-x64/lib/node_modules/npm/node_modules/umask/README.md node-v6.10.3-linux-x64/lib/node_modules/npm/node_modules/umask/.npmignore [root@liumiaocn nodejs]#
设置环境变量
[root@liumiaocn bin]# [root@liumiaocn bin]# export PATH=$PATH:/usr/local/nodejs/node-v6.10.3-linux-x64/bin [root@liumiaocn bin]#
这样设定的环境变量需要每次都设定,如果需要长久设定的话,请根据具体情况设定到/etc/profile或者.bashrc或.profile中。
确认版本
[root@liumiaocn ~]# node --version v6.10.3 [root@liumiaocn ~]# npm --version 3.10.10 [root@liumiaocn ~]#
Hubot Generator
安装Hubot Generator,之前我们在使用Racher的时候的自定义模板时也有使用类似的功能,其实就是yoman,提供一些简化我们使用方式。安装命令
# npm install -g yo generator-hubot
创建一个聊天机器人
使用刚刚安装的Hubot Generator创建一个名为lili的聊天机器人,只需要注意一点,请用普通用户进行创建。安装结果确认
安装之后,确认刚刚使用yoman创建的名为lili的聊天机器人,以下是详细信息:[admin@liumiaocn myhubot]$ pwd /home/admin/myhubot [admin@liumiaocn myhubot]$ ls bin external-scripts.json hubot-scripts.json node_modules package.json Procfile README.md scripts [admin@liumiaocn myhubot]$ cd bin [admin@liumiaocn bin]$ ls hubot hubot.cmd [admin@liumiaocn bin]$
执行确认
[admin@liumiaocn myhubot]$ pwd /home/admin/myhubot [admin@liumiaocn myhubot]$ bin/hubot lili> [Tue May 30 2017 05:47:15 GMT-0400 (EDT)] WARNING Loading scripts from hubot-scripts.json is deprecated and will be removed in 3.0 (https://github.com/github/hubot-scripts/issues/1113) in favor of packages for each script. our hubot-scripts.json is empty, so you just need to remove it. [Tue May 30 2017 05:47:15 GMT-0400 (EDT)] ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. `heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s | grep web-url | cut -d= -f2)` [Tue May 30 2017 05:47:15 GMT-0400 (EDT)] INlt redis on localhost:6379 lili>
可以看到其提示的有ERROR的信息,前面也有提到,Hubot缺省支持Heroku,并将Redis作为其持久方案,如果不希望使用Redis的话,可以通过直接删除如下文件中的hubot-heroku-keepalive和hubot-redis-brain即可。
[admin@liumiaocn myhubot]$ cat external-scripts.json [ "hubot-diagnostics", "hubot-help", "hubot-heroku-keepalive", "hubot-google-images", "hubot-google-translate", "hubot-pugme", "hubot-maps", "hubot-redis-brain", "hubot-rules", "hubot-shipit" ][admin@liumiaocn myhubot]$
hubot-scripts.json内容为空,所以也出了一个WARNING,不想看到的话,删除即可。
[admin@liumiaocn myhubot]$ cat hubot-scripts.json [][admin@liumiaocn myhubot]$
结果确认
[admin@liumiaocn myhubot]$ bin/hubot lili>
可以看到聊天机器人lili已经启动了,接下来可以看看lili能做什么了,使用lili help可以看到其能做的所有事情。
[admin@liumiaocn myhubot]$ bin/hubot lili> lili help
lili> Shell: lili adapter - Reply with the adapter
lili animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
lili echo <text> - Reply back with <text>
lili help - Displays all of the help commands that Hubot knows about.
lili help <query> - Displays all help commands that match <query>.
lili image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
lili map me <query> - Returns a map view of the area returned by `query`.
lili mustache me <url|query> - Adds a mustache to the specified URL or query result.
lili ping - Reply with pong
lili pug bomb N - get N pugs
lili pug me - Receive a pug
lili the rules - Make sure hubot still knows the rules.
lili time - Reply with current time
lili translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
lili translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
ship it - Display a motivation squirrel
使用lili ping,她会回答pong
lili> lili ping lili> PONG lili>
问她规矩,她会背诵机器人三原则
lili> lili the rules lili> 0. A robot may not harm humanity, or, by inaction, allow humanity to come to harm. 1. A robot may not injure a human being or, through inaction, allow a human being to come to harm. 2. A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law. 3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law. lili>
唯一一条看起来有用的命令,是询问时间
lili> lili time lili> Server time is: Tue May 30 2017 06:51:28 GMT-0400 (EDT) lili>
总结
通过Hubot Generator就可以轻松创建lili这样一个聊天机器人,但是目前看起来她还完全不会聊天。唯一看似乎有用的time命令似乎还不如自己直接敲date,但是这只是一个例子,我们可以自己写自己的scripts以满足自己的实际的需求。而这些类似的Scripts已经有了一些,而Hubot的本意则正是希望能够创建一个生态环境,一个大体根Ansible的galaxy或者docker的dockerhub类似程度的生态圈吧。通过ChatOps方式的整合,是不是也可以将语音识别/自动运维/人工智能等不断的集成进取呢,真正社区的推动才会使得Hubot真正的发展,是否会有一个完整链条的生态圈出现目前还无法断言,但不妨拭目以待.相关文章推荐
- chatops--rocketchat+hubot
- Watin与Httpwatch工具结合进行测试
- ADB(调试桥)- 设备管理工具
- 项目管理-工具
- mprop工具
- java开发常用工具和优秀网站
- 2.Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程
- 代码格式化工具
- Jquery时间验证和转换工具小例子
- profile工具
- 一款很不错的html转xml工具-Html Agility Pack
- 极力推荐的开发工具 anjuta+glade
- MySQL命令行工具
- 代码分析工具findbug简介和使用
- SQL Server 2005 企业版没有 Management Studio管理工具 解决办法
- 反汇编动态追踪工具Ollydbg. ALD,ddd,dbg,edb...
- 线上引流压测工具Meteor
- java常用的发送http请求的工具方法
- GoldenGate的Logdump工具使用简介