Created
October 14, 2013 07:21
-
-
Save piykumar/6972003 to your computer and use it in GitHub Desktop.
logstash output to couchbase
This file contains hidden or 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
# Output to Couchbase | |
# :hostname => "localhost" # :port => 8091 | |
# :password => "secret" # :username => 'protected' | |
# :bucket => "default" # :pool => "default" | |
# :timeout => 3_000_000 | |
# | |
require "logstash/outputs/base" | |
require "logstash/namespace" | |
class LogStash::Outputs::Couchbase < LogStash::Outputs::Base | |
config_name "couchbase" | |
milestone 1 | |
config :hostname, :validate => :string, :required => true | |
config :port, :validate => :integer, :required => true | |
config :pool, :validate => :string, :required => true | |
config :bucket, :validate => :string, :required => true | |
config :username, :validate => :string, :required => true | |
config :password, :validate => :string, :required => true | |
config :isodate, :validate => :boolean, :default => false | |
config :ttl, :validate => :number, :default => 3000, :required => false | |
public | |
def register | |
require 'couchbase' | |
require 'msgpack' | |
require 'json' | |
require 'active_support/core_ext/hash' | |
# Connection | |
Couchbase.connection_options = {:async => true} | |
conn_couchbase = Couchbase.connect(:hostname => hostname, | |
:port => port, | |
:pool => pool, | |
:username => username, | |
:password => password, | |
:bucket => bucket) | |
end # def register | |
public | |
def receive(event) | |
return unless output?(event) | |
begin | |
if @isodate | |
document = event.to_hash | |
else | |
document = event.to_hash.merge("@timestamp" => event["@timestamp"].to_json) | |
end | |
#Insert | |
rescue => e | |
@logger.warn("Failed to send event to Couchbase", :event => event, :exception => e, | |
:backtrace => e.backtrace) | |
end | |
end # def receive | |
end # class LogStash::Outputs::Couchbase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment