diff --git a/Gemfile b/Gemfile index 5b3725f6b..a7afed42c 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ gem "redis" # outputs/redis, License: MIT-style gem "gelf" # outputs/gelf, # License: MIT-style gem "statsd-ruby", "~> 0.3.0" # outputs/statsd, # License: As-Is gem "gmetric", "~> 0.1.3" # outputs/ganglia, # License: MIT +gem "xmpp4r", "~> 0.1.3" # outputs/xmpp, # License: As-Is # For testing/dev group :development do diff --git a/lib/logstash/outputs/ganglia.rb b/lib/logstash/outputs/ganglia.rb index c8b3d94b3..8791ad3af 100644 --- a/lib/logstash/outputs/ganglia.rb +++ b/lib/logstash/outputs/ganglia.rb @@ -41,11 +41,21 @@ class LogStash::Outputs::Ganglia < LogStash::Outputs::Base public def receive(event) # gmetric only takes integer values, so convert it to int. + case @type + when "string" + localvalue = event.sprintf(@value) + when "float" + localvalue = event.sprintf(@value).to_f + when "double" + localvalue = event.sprintf(@value).to_f + else # int8|uint8|int16|uint16|int32|uint32 + localvalue = event.sprintf(@value).to_i + end Ganglia::GMetric.send(@host, @port, { :name => event.sprintf(@metric), :units => @units, :type => @type, - :value => event.sprintf(@value).to_i, + :value => localvalue, :tmax => @tmax, :dmax => @dmax }) diff --git a/lib/logstash/outputs/xmpp.rb b/lib/logstash/outputs/xmpp.rb new file mode 100644 index 000000000..c2099a0f0 --- /dev/null +++ b/lib/logstash/outputs/xmpp.rb @@ -0,0 +1,37 @@ +require "logstash/outputs/base" +require "logstash/namespace" +require "xmpp4r" + +# This output allows you to pull metrics from your logs and ship them to +# XMPP/Jabber. +class LogStash::Outputs::Xmpp< LogStash::Outputs::Base + config_name "xmpp" + + # Connection information for server + config :resource, :validate => :string, :required => true + config :password, :validate => :string, :required => true + config :targets, :validate => :array, :required => true + + # The message to send. This supports dynamic strings like %{@source_host} + config :message, :validate => :string, :required => true + + def register + @client = connect + end # def register + + def connect + client = Client.new(JID::new(@resource)) + client.connect + client.auth(@password) + end # def connect + + public + def receive(event) + t = event.sprintf(@message) + @targets.each do |target| + msg = Message::new("#{target}", t) + msg.type=:chat + @client.send(msg) + end + end # def receive +end # class LogStash::Outputs::Xmpp diff --git a/logstash.gemspec b/logstash.gemspec index 3ee425ef2..35aa150e4 100644 --- a/logstash.gemspec +++ b/logstash.gemspec @@ -47,6 +47,7 @@ Gem::Specification.new do |spec| spec.add_dependency "gelf" # outputs/gelf spec.add_dependency "statsd-ruby" # outputs/statsd spec.add_dependency "gmetric" # outputs/ganglia + spec.add_dependency "xmpp4r" # outputs/xmpp # For the 'grok' filter spec.add_dependency("jls-grok", "~> 0.4.7")