Sha256: 272980d1047a09e70527865da323e567f09dfa82b808b557721134362812eb18

Contents?: true

Size: 637 Bytes

Versions: 46

Compression:

Stored size: 637 Bytes

Contents

# frozen_string_literal: true

require "socket"

module ExceptionHandling
  module Sensu
    LEVELS = {
      warning: 1,
      critical: 2
    }.freeze

    class << self
      def generate_event(name, message, level = :warning)
        status = LEVELS[level] or raise "Invalid alert level #{level}"

        event = { name: ExceptionHandling.sensu_prefix.to_s + name, output: message, status: status }

        send_event(event)
      end

      def send_event(event)
        Socket.tcp(ExceptionHandling.sensu_host, ExceptionHandling.sensu_port) do |sock|
          sock.send(event.to_json, 0)
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
exception_handling-2.17.0.pre.tstarck.1 lib/exception_handling/sensu.rb
exception_handling-2.16.0 lib/exception_handling/sensu.rb
exception_handling-2.15.0 lib/exception_handling/sensu.rb
exception_handling-2.14.0 lib/exception_handling/sensu.rb
exception_handling-2.14.0.pre.gk.1 lib/exception_handling/sensu.rb
exception_handling-2.14.0.pre.gk.0 lib/exception_handling/sensu.rb
exception_handling-2.13.0 lib/exception_handling/sensu.rb
exception_handling-2.13.0.pre.dc.0 lib/exception_handling/sensu.rb
exception_handling-2.12.0 lib/exception_handling/sensu.rb
exception_handling-2.12.0.gfaza.1 lib/exception_handling/sensu.rb
exception_handling-2.11.4.gfaza.1 lib/exception_handling/sensu.rb
exception_handling-2.11.3 lib/exception_handling/sensu.rb
exception_handling-2.11.2 lib/exception_handling/sensu.rb
exception_handling-2.11.1 lib/exception_handling/sensu.rb
exception_handling-2.11.0 lib/exception_handling/sensu.rb
exception_handling-2.10.0 lib/exception_handling/sensu.rb
exception_handling-2.10.0.pre.2 lib/exception_handling/sensu.rb
exception_handling-2.10.0.pre.1 lib/exception_handling/sensu.rb
exception_handling-2.9.0 lib/exception_handling/sensu.rb
exception_handling-2.9.0.pre.1 lib/exception_handling/sensu.rb