首页 > 学院 > 操作系统 > 正文

bearychat+hubot chatops运维机器人

2024-06-28 16:00:31
字体:
来源:转载
供稿:网友

1.安装nodejs

yum安装:[root@node1 ~]# yum install -y epel-release[root@node1 ~]# yum install -y npm[root@node1 ~]# npm -version3.10.8[root@node1 ~]# node -vv6.9.1二进制包安装最新版:官网下载地址:https://nodejs.org/en/download/[root@node1 ~]# tar xf node-v6.9.5-linux-x64.tar.xz[root@node1 ~]# mv node-v6.9.5-linux-x64 /usr/local/nodejs[root@node1 ~]# vim /etc/PRofileexport NODE_HOME=/usr/local/nodejsexport PATH=$NODE_HOME/bin:$PATH[root@node1 ~]# source /etc/profile[root@node1 ~]# npm -version3.10.10[root@node1 ~]# node -vv6.9.5

2. 安装hubot

[root@node1 ~]# npm install -g hubot coffee-script yo generator-hubot[root@node1 ~]# mkdir myhubot && cd myhubot[root@node1 myhubot]# yo hubot (提示没有权限)/usr/local/nodejs/lib/node_modules/yo/node_modules/mkdirp/index.js:90 throw err0; ^Error: EACCES: permission denied, mkdir '/root/.config' at Error (native) at Object.fs.mkdirSync (fs.js:922:18) at sync (/usr/local/nodejs/lib/node_modules/yo/node_modules/mkdirp/index.js:71:13) at Function.sync (/usr/local/nodejs/lib/node_modules/yo/node_modules/mkdirp/index.js:77:24) at Object.get (/usr/local/nodejs/lib/node_modules/yo/node_modules/configstore/index.js:38:13) at Object.Configstore (/usr/local/nodejs/lib/node_modules/yo/node_modules/configstore/index.js:27:44) at new Insight (/usr/local/nodejs/lib/node_modules/yo/node_modules/insight/lib/index.js:37:34) at Object.<anonymous> (/usr/local/nodejs/lib/node_modules/yo/lib/cli.js:172:11) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10)[root@node1 myhubot]# chmod g+w /root (修改root目录权限)[root@node1 myhubot]# yo hubot? ==========================================================================We're constantly looking for ways to make yo better! May we anonymously report usage statistics to improve the tool over time? More info: https://github.com/yeoman/insight & http://yeoman.io========================================================================== Yes _____________________________ / / /// | Extracting input for | ///// _____ | self-replication process | /////// /_____/ / / ======= |[^_//_]| /---------------------------- | | _|___@@__|__ +===+/ /// /_/ | |_/ /// HUBOT/// |___//// / // / / +---+ /____/ | | | //| +===+ /// |xx| ? Owner XXX <XXX@163.com>? Bot name myhubot? Description A simple helpful robot for your Company? Bot adapter campfire create bin/hubot create bin/hubot.cmd create Procfile create README.md create external-scripts.json create hubot-scripts.json create .gitignore create package.json create scripts/example.coffee create .editorconfig _____________________________ _____ / / / / | Self-replication process | | | _____ | complete... | |__//| /_____/ / Good luck with that. / |//+ |[^_//_]| /---------------------------- | | _|___@@__|__ +===+/ /// /_/ | |_/ /// HUBOT/// |___//// / // / / +---+ /____/ | | | //| +===+ /// |xx| myhubot@0.0.0 /root/myhubot├─┬ hubot@2.19.0 │ ├── async@0.9.2 │ ├─┬ chalk@1.1.3 │ │ ├── ansi-styles@2.2.1 │ │ ├── escape-string-regexp@1.0.5 │ │ ├─┬ has-ansi@2.0.0 │ │ │ └── ansi-regex@2.1.1 │ ││ │ ├─┬ connect@2.30.2 ......[root@node1 myhubot]# chmod g-w /root (将root目录权限恢复原状)[root@node1 myhubot]# npm install hubot-bearychat --savemyhubot@0.0.0 /root/myhubot└─┬ hubot-bearychat@0.3.1 ├─┬ bearychat@0.1.0 │ ├── babel-plugin-add-module-exports@0.2.1 │ ├─┬ isomorphic-fetch@2.2.1 │ │ ├─┬ node-fetch@1.6.3 │ │ │ ├─┬ encoding@0.1.12 │ │ │ │ └── iconv-lite@0.4.15 │ │ │ └── is-stream@1.1.0 │ │ └── whatwg-fetch@2.0.2 │ └── urijs@1.18.5 └─┬ ws@1.1.1 ├── options@0.0.6 └── ultron@1.0.2

安装shell 命令脚本支持模块:

[root@node1 myhubot]# npm install hubot-script-shellcmdmyhubot@0.0.0 /root/myhubot└── hubot-script-shellcmd@0.0.16[root@node1 myhubot]# cp -R node_modules/hubot-script-shellcmd/bash ./修改一下external-scripts.json,添加模块:hubot-script-shellcmd[root@node1 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", "hubot-script-shellcmd" //新增部分][root@node1 myhubot]# cd bash/handlers/[root@node1 handlers]# lshelloworld update新增脚本[root@node1 handlers]# cat disk #!/bin/bashdf -h[root@node1 handlers]# chmod +x disk

3. 注册bearychat添加机器人

https://www.bearychat.com 注册并登陆 这里写图片描述 这里写图片描述 这里写图片描述

注意:

复制Hubot Token 这个很重要Hubot URL 端口可以随意指定【export EXPRESS_PORT=9090】

下载bearychat客户端或者直接使用网页版都可以

配置hubot并启动

此处的token就是第三步添加机器人时显示的token多个使用逗号分隔[root@node1 myhubot]# export HUBOT_BEARYCHAT_TOKENS=bd00e55956a3759886c21c1ac1fd17dd[root@node1 myhubot]# export HUBOT_BEARYCHAT_MODE=rtm[root@node1 myhubot]# export EXPRESS_PORT=9090[root@node1 myhubot]# nohup ./bin/hubot -a bearychat 2&1> hubot.log[root@node1 myhubot]# netstat -tnlp|grep 9090tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 54886/node 为了以后启动方便可以直接将变量写人文件:[root@node1 myhubot]# cat /etc/profile.d/myhubot.sh export HUBOT_BEARYCHAT_TOKENS=bd00e5595121249886c21c1ac1fd17ddexport HUBOT_BEARYCHAT_MODE=rtmexport EXPRESS_PORT=9090[root@node1 myhubot]# source /etc/profile 这样以后就无需手动再次export

5. 客户端登录并测试

这里写图片描述

6. 机器人脚本示例

[root@node1 ~]# cd myhubot/scripts[root@node1 scripts]# vim example.coffee (编辑并修改) ....# Uncomment the ones you want to try and experiment with.## These are from the scripting documentation: https://github.com/github/hubot/blob/master/docs/scripting.mdmodule.exports = (robot) -> robot.hear /jevic/i, (res) -> res.send "https://jevic.github.io"# robot.respond /open the (.*) doors/i, (res) ->....

这里写图片描述

重启hubot [root@node1 ~]# nohup ./bin/hubot -a bearychat 2&1>> hubot.log &

测试

这里写图片描述

参考链接用slack和hubot搭建你自己的运维机器人hubot-bearychathttps://hubot.github.com
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表