Sha256: 564ed8378ab97bff0c261b944493fe355b339ae5a492aa42d1e4b1d0e19d0139

Contents?: true

Size: 1.64 KB

Versions: 21

Compression:

Stored size: 1.64 KB

Contents

#!/usr/bin/env ruby

# Formats entity data for presentation by the API methods in Flapjack::API.
# Currently this just aggregates all of the check data for an entity, leaving
# clients to make any further calculations for themselves.

require 'sinatra/base'

require 'flapjack/api/entity_check_presenter'
require 'flapjack/data/entity_check'

module Flapjack

  class API < Sinatra::Base

    class EntityPresenter

      def initialize(entity, options = {})
        @entity = entity
        @redis = options[:redis]
      end

      def outages(start_time, end_time)
        checks.collect {|c|
          {:check => c, :outages => check_presenter(c).outages(start_time, end_time)}
        }
      end

      def unscheduled_maintenance(start_time, end_time)
        checks.collect {|c|
          {:check => c, :unscheduled_maintenance =>
            check_presenter(c).unscheduled_maintenance(start_time, end_time)}
        }
      end

      def scheduled_maintenance(start_time, end_time)
        checks.collect {|c|
          {:check => c, :scheduled_maintenance =>
            check_presenter(c).scheduled_maintenance(start_time, end_time)}
        }
      end

      def downtime(start_time, end_time)
        checks.collect {|c|
          {:check => c, :downtime =>
            check_presenter(c).downtime(start_time, end_time)}
        }
      end

    private

      def checks
        @check_list ||= @entity.check_list
      end

      def check_presenter(check)
        entity_check = Flapjack::Data::EntityCheck.for_entity(@entity, check,
          :redis => @redis)
        presenter = Flapjack::API::EntityCheckPresenter.new(entity_check)
      end

    end

  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
flapjack-0.6.43 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.42 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.41 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.40 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.39 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.38 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.37 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.36 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.35 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.34 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.33 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.32 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.31 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.30 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.29 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.28 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.27 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.26 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.25 lib/flapjack/api/entity_presenter.rb
flapjack-0.6.24 lib/flapjack/api/entity_presenter.rb