Sha256: 027d83a222655ef6698bc168fa9b396ead9ceb0c1c1837e46034bb9eb08b35c6

Contents?: true

Size: 743 Bytes

Versions: 1

Compression:

Stored size: 743 Bytes

Contents

require 'socket'
require 'json'

class Riemann::Babbler::Plugin::ResponderUdp < Riemann::Babbler::Plugin

  def init
    plugin.set_default(:port, opts.riemann.responder_udp_port)
  end

  def process(data, src)
    begin
      msg = JSON.parse(data)
      msg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
      report(msg)
      src.reply "sended\n"
    rescue
      log :error, "Failed to send message: #{data.inspect}"
      src.reply "failed to send: #{data.inspect}\n"
    end    
  end

  def run!
    log :unknown, "Start udp server at #{plugin.port}"
    Socket.udp_server_loop(plugin.port) do |data, src|
      log :debug, "recived data: #{data.inspect}, from client: #{src.inspect}"
      process(data, src) 
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-babbler-2.0.9 lib/riemann/babbler/plugins/responder_udp.rb