miércoles, octubre 10, 2012

Installing And Running Hubot, Terminator is Here


In current post we are going to see how to install hubot and make it work over XMPP protocol (using open fire server),  and how can help us during our daily work.

Hubot is a robot which belongs to your chat infrastructure as one more user, which you can talk with him. Hubot can help you automate a lot of tasks, like deploy a site, manage your Pomodoro,   or managing issue system to cite a few of them. Hubot is written in CoffeScript on Node.js, keep in mind that Hubot can be extended with CoffeScript and you can easily extend it.

This post is written using Ubuntu, so if you are using any other OS, you only have to modify the way of how components are installed.

First of all (I assume you have a JVM installed), you must install npm and node.js. For this I have used apt-get.
sudo apt-get install nodejs npm
Next step is installing Hubot dependencies by running next apt-get command.
apt-get install build-essential libssl-dev git-core redis-server libexpat1-dev
Then we need to install CoffeScript. So we can run next command:
npm install -g coffee-script
And finally we are going to install Hubot in /opt directory. Obviously could be any other one.
cd /opt
git clone git://github.com/github/hubot.git && cd hubot
npm install
Hubot is installed, to see if it works simply run from installation directory:
alex@grumpy:/opt/hubot$ ./bin/hubot
and Hubot shell will be started. This shell is really useful for testing purposes but not for production environment.
Hubot> hubot ping
Hubot> PONG
which will produce a Pong message.

Now it is time to install Openfire server so we can communicate with Hubot using XMPP protocol instead of shell. Of course you could choose any other XMPP server, but for now Openfire is used.

To install it, download it from openfire site, and extract it to /opt directory.
tar -xzvf openfire_<version>.tar.gz
mv openfire /opt
Then it is time to configure Openfire server, we are going to use embedded database but of course you can configure an external database such as MySQL or Oracle.

A web-based wizard driven setup and configuration tool is built in Openfire, so let's start Openfire server for the first time and configure typical parameters like administrator username, server name, ...
$OPENFIRE_HOME/bin/openfire start
and access to http://localhost:9090.

Then log in as admin into Openfire and create first two users, developer and hubot. So go to Users/Groups -> Create New User, and fill required information for both users.


Next step is creating a room where all users that want to interact with Hubot will join. So go to Group Chat -> Create New Room and create a new room. In our case we are going to call hubot.


and finally we must disable TLS security, there is an issue between Openfire TLS version and node.js XMPP module so if you are using Openfire, you should disable it.


Next step is checking that developer user has access to hubot chatroom and the account is correctly configured, so we can open our XMPP client (in our case Spark) but should be work with any other one and verify that we can connect.

If you are using Spark, log in with developer account and in Actions menu you will find Join Conference room option. Setthere and choose previously created room (hubot). And now you know you have configured correctly XMPP part.

And now it is time for Hubot. First of all we are going to create a bot called my-bot:
alex@grumpy:/opt/hubot$ ./bin/hubot -c ./my-bot
Then enter into my-bot directory and open package.json and add next dependencies which configure  adapter so Hubot can use XMPP protocol for communication:
"dependencies": {
    "hubot": "2.3.2",
    "hubot-scripts": ">= 2.1.0",
    "optparse": "1.0.3",
    "node-xmpp": "0.3.2",
    "hubot-xmpp": "0.1.0",
    "htmlparser": "1.7.6",
    "soupselect": "0.2.0",
    "underscore": "1.3.3",
    "underscore.string": "2.2.0rc"
  }
Then before starting Hubot, you must install XMPP adapter. Run from hubot directory npm install, and XMPP extension will be installed into hubot.
alex@grumpy:/opt/hubot/my-bot$ npm install
And now we are ready to start using Hubot and Openfire.

We are going to start by adding environment variables to configure XMPP adapter.
export HUBOT_XMPP_USERNAME=hubot@grumpy
export HUBOT_XMPP_PASSWORD=<password>
export HUBOT_XMPP_ROOMS=hubot
Note that username should be accompanied for server name which in my case is grumpy. And finally it is time to start Hubot.
alex@grumpy:/opt/hubot/my-bot$ ./bin/hubot --adapter xmpp
And you will see at Spark your new friend (if you have already add hubot as a friend).


And after you check that we can go to hubot-scripts and download and install the useful ones depending on our environment.

In next video you could see a screencast of Hubot In Action with some scripts that I use.



I wish you have liked Hubot,

We keep learning,
Alex.


A Time For Us, At Last To See, A Life Worthwhile, For You And Me (A Time For Us - Andy Williams)
Music: http://www.youtube.com/watch?v=sRnx-s1TQbU

0 comentarios:

Donate If You Can and Find Post Useful