Created
December 8, 2013 20:15
-
-
Save cutoffthetop/7863289 to your computer and use it in GitHub Desktop.
Custom Logstash output for HBase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'logstash/outputs/base' | |
require 'logstash/namespace' | |
class LogStash::Outputs::HBase < LogStash::Outputs::Base | |
config_name 'hbase' | |
milestone 2 | |
# The HBase server uri | |
config :uri, :validate => :string, :required => false, :default => 'localhost' | |
# The table name to use | |
config :table_name, :validate => :string, :required => true | |
# Optionally define columns | |
config :columns, :validate => :array, :require => false, :default => ['cf1'] | |
public | |
def register | |
require 'rubygems' | |
require 'hbaserb' | |
client = HBaseRb::Client.new(@uri) | |
@logger.debug('Register: established hbase connection') | |
if client.has_table?(@table_name) | |
args = [@table_name] + @columns | |
@table = client.create_table(*args) | |
else | |
@table = client.get_table(@table_name) | |
end | |
end | |
public | |
def receive(event) | |
document = event.to_hash | |
@table.mutate_row(document['_id'], {'cf1:col' => document['message']}) | |
end | |
def teardown | |
@client.close | |
@logger.debug('Teardown: closed hbase connection') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmmm, "no such file to load", not so hard to resolve guys, did you include "https://github.com/bmuller/hbaserb"?