Sha256: 55b91fe15d8a74655a9a27278f2a2168d364b8b35d410b3fc32cb1b9521ec1fb

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

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

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

  def init
    plugin.set_default(:port, opts.riemann.responder_http_port)
    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 0.0.0.0:#{plugin.port}"
    ::Net::HTTP::Server.run(:port => plugin.port) 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

5 entries across 5 versions & 1 rubygems

Version Path
riemann-babbler-2.1.2 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.1.1 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.1.0 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.0.9 lib/riemann/babbler/plugins/responder_http.rb
riemann-babbler-2.0.8 lib/riemann/babbler/plugins/responder_http.rb