Since i’m a RUBY lover, i decided to use this couchdb ruby wrapper. SInce my requirement with CouchDB was pretty simple, this wrapper itself was sufficient for me. This wrapper can be used to perform any operations like, reading,writing,deleting Documents as well as Databases. This wrapper basically uses the ruby http library to talk to the CouchDB’s rest api. By default couchdb is available in most of the Linux respositories. for windows and mac, the files are available in the CouchDB website itself.
for example, for ubuntu/debian, below command will install couchdb server.
sudo apt-get install couchdb -y
By default, the couchDB package comes with a web frontend called “Futon” which can be accessed via browsers ugin the below url,
Below is the screenshot of the Futon frontend.
We can perform all the operations through this web interface also. So i created a database, and created a document for each host with required fields. Now these documents can be accessed via the rest api in JSON format. so that my ruby script can fetch all the necessary data and can compose the exact url for fetching the check results for corresponding hosts.
Below is a sample read operation that we can perform through our ruby scripts. But before using the operation, we need to include the wrapper into our script. For that we need to add ‘require ./couch.rb’, we can use both relative or absolute path. once the wrapper is included,we can start performing operations with the CouchDB.
server = Couch::Server.new("localhost", "5984") res = server.get("/foo/document_id") json = res.body puts json
The operation will read the document and will convert it into JSON using the json ruby library. Now i can use the JSON data to collect the required fields so that my script can form the exact fetch url for each host and can perform the result fetch. There is couchdb gem for ruby, which can perform more operations.
Apart from this, CouchDB has another important feature ”MAPREDUCE”, yes it can perform MapReduce, i’m trying to find if mapreduce can help me, so that i can extend my app to do more things. Once if i get any weird idea with MapReduce i will udapte this blog with that also.