Sha256: ba04ad444ad5c79d2919852748fe9112677043222c9a33b72b0e46e01a1e09a7

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

class ServerStatusApp < Sinatra::Base
  set :root, GEM_ROOT
  set :server, :thin

  class << self
    def check server
      server_config = ServerStatusConfig.servers[server.to_sym]
      client = ServerStatusClient.new server_config
      status_code = client.request.to_s
      Status.new server, server_config[:description.to_s], status_code, client.is_port_open?
    end
  end

  get '/' do
    @server_status = ServerStatusConfig.servers.keys.collect do |server|
      ServerStatusApp.check server
    end

    slim :index
  end

  get '/servers' do
    ServerStatusConfig.servers.keys.to_json
  end

  get '/:server/status' do
    ServerStatusApp.check(params[:server].to_sym).to_json
  end

  class Status
    attr_reader :code, :name, :description

    def initialize name, description, code, is_open
      @code, @name, @description, @is_open = code.to_i, name, description, is_open
    end

    def is_open?
      @is_open
    end

    def to_json
      {name: @name, code: @code, description: @description, is_open: @is_open}.to_json
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
server_status-0.1.0 lib/server_status/app.rb