Sha256: 204a11d352a9b00adb968a3f85c09190a6642aa9c55f48425d8531d1a952f962

Contents?: true

Size: 849 Bytes

Versions: 7

Compression:

Stored size: 849 Bytes

Contents

name 'http server'
always_start true

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

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

helpers do
  @s_time = Time.now
  def json_info
    {
      :version => Kurchatov::VERSION,
      :uptime => (Time.now - @s_time).to_i,
      :monitor => monitor.inspect,
      :fqdn => Kurchatov::Config[:host],
      :app_name => 'kurchatov'
    }.to_json + "\n"
  end
end

run do
  @server ||= TCPServer.new(plugin.host, plugin.port)
  loop do
    client = @server.accept
    response = json_info
    client.gets
    headers = "HTTP/1.1 200 OK\r\n" +
      "Server: Kurchatov Ruby\r\n" +
      "Content-Length: #{response.bytesize}\r\n" +
      "Content-Type: application/json\r\n\r\n"
      client.print headers
      client.print response
      client.close
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kurchatov-0.4.7 lib/kurchatov/responders/http_server.rb
kurchatov-0.4.6 lib/kurchatov/responders/http_server.rb
kurchatov-0.4.5 lib/kurchatov/responders/http_server.rb
kurchatov-0.4.4 lib/kurchatov/responders/http_server.rb
kurchatov-0.4.3 lib/kurchatov/responders/http_server.rb
kurchatov-0.4.2 lib/kurchatov/responders/http_server.rb
kurchatov-0.4.1 lib/kurchatov/responders/http_server.rb