Sha256: 4c1dcc0926541292507fc57fc19f7adb0c82a3b96823796cd978b6e272818c19

Contents?: true

Size: 1.14 KB

Versions: 22

Compression:

Stored size: 1.14 KB

Contents

require 'net/http/server'
require 'json'

class Riemann::Babbler::Plugin::ResponderHttp < Riemann::Babbler::Plugin

  def init
    host, port = opts.riemann.responder_bind_http.split(':')
    plugin.set_default(:port, port)
    plugin.set_default(:host, host)
    plugin.set_default(:started_at, Time.now.to_i)
  end

  def info
    {
        :version => Riemann::Babbler::VERSION,
        :ruby    => "#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}",
        :uptime  => Time.now.to_i - plugin.started_at,
        :errors  => opts.errors.to_hash,
        :config  => opts.riemann.to_hash
    }.to_json
  end

  def status_ok
    {:status => 'ok'}.to_json
  end

  def run!
    log :unknown, "Start responder #{plugin.host}:#{plugin.port}"
    ::Net::HTTP::Server.run(:port => plugin.port, :host => plugin.host) do |request, _|
      log :debug, "Responder request: #{request}"
      case
        when request[:uri][:path] == "/kill" #&& request[:method] == "POST"
          [200, { 'Content-Type' => 'application/json' }, [status_ok]]
          Process.kill('TERM', $$)
      else
        [200, { 'Content-Type' => 'application/json' }, [info]]
      end
    end
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.8.4 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.8.3 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.8.2 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.8.1 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.8.0 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.6.0 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.9 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.8 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.7 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.6 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.5 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.4 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.3 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.2 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.1 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.5.0 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.1.5 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.1.4 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/plugins/responder_http.rb