Sha256: fe3687809ef94fed98bac33a96703105ddc17c22113fc9ca2eb48b26524d1765

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

require 'net/http'
require 'timeout'

module Ring
class SQA
class Alarm

  class Collector
    URL     = 'http://sqa-collector.infra.ring.nlnog.net/'
    TIMEOUT = 10
    def send opts
      json = JSON.pretty_generate( {
        :alarm_buffer => opts[:alarm_buffer].exceeding_nodes,
        :nodes        => opts[:nodes].all,
        :short        => opts[:short],
        :long         => opts[:long],
        :status       => opts[:status],
        :afi          => opts[:afi],
      })
      post json
    rescue => error
      Log.error "Post raised '#{error.class}' with message '#{error.message}'"
    end

    private

    def post json
      Thread.new do
        begin
          Timeout::timeout(TIMEOUT) do
            uri = URI.parse URL
            http = Net::HTTP.new uri.host, uri.port
            http.use_ssl = true if uri.scheme == 'https'
            http.post uri.path, json
          end
        rescue Timeout::Error
          Log.error "Post timed out"
        end
      end
    end
  end

end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ring-sqa-0.2.0 lib/ring/sqa/alarm/collector.rb
ring-sqa-0.1.12 lib/ring/sqa/alarm/collector.rb