Sha256: 1f73711185183c4125740d2177b028b98364ae6d496f49df64105ff4ef6a15b8

Contents?: true

Size: 721 Bytes

Versions: 18

Compression:

Stored size: 721 Bytes

Contents

name 'udp responder'
always_start true

default[:host], default[:port] = Kurchatov::Config[:udp_responder].to_s.split(":")

run_if do
  !!Kurchatov::Config[:udp_responder]
end

helpers do
  def process(data, src)
    begin
      hash = JSON.parse(data)
      hash = hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
      event(hash)
      src.reply "sended\n\n"
      Log.debug("Send event from udp responder: #{hash.inspect}")
    rescue => e
      src.reply "failed to send: #{data.inspect}\n"
      Log.error("Failed parse #{data.inspect}, #{e.class}: #{e}\n #{e.backtrace.join("\n")}")
    end
  end
end

run do
  Socket.udp_server_loop(plugin.host, plugin.port) do |data, src|
    process(data, src)
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
kurchatov-0.3.8 lib/kurchatov/responders/udp.rb
kurchatov-0.3.7 lib/kurchatov/responders/udp.rb
kurchatov-0.3.6 lib/kurchatov/responders/udp.rb
kurchatov-0.3.5 lib/kurchatov/responders/udp.rb
kurchatov-0.3.4 lib/kurchatov/responders/udp.rb
kurchatov-0.3.3 lib/kurchatov/responders/udp.rb
kurchatov-0.3.2 lib/kurchatov/responders/udp.rb
kurchatov-0.3.1 lib/kurchatov/responders/udp.rb
kurchatov-0.3.0 lib/kurchatov/responders/udp.rb
kurchatov-0.2.9 lib/kurchatov/responders/udp.rb
kurchatov-0.2.8 lib/kurchatov/responders/udp.rb
kurchatov-0.2.7 lib/kurchatov/responders/udp.rb
kurchatov-0.2.6 lib/kurchatov/responders/udp.rb
kurchatov-0.2.5 lib/kurchatov/responders/udp.rb
kurchatov-0.2.4 lib/kurchatov/responders/udp.rb
kurchatov-0.2.3 lib/kurchatov/responders/udp.rb
kurchatov-0.2.2 lib/kurchatov/responders/udp.rb
kurchatov-0.2.1 lib/kurchatov/responders/udp.rb