Sha256: a4d08c148d13d84b071c25a20c0cff42343dc07af78f074b32fc6dcb785fe131

Contents?: true

Size: 1.56 KB

Versions: 14

Compression:

Stored size: 1.56 KB

Contents

# Send a notice to Scout (http://scoutapp.com/).
#
# client_key - The String client key.
# plugin_id  - The String plugin id.

require 'net/http'
require 'uri'

module God
  module Contacts

    class Scout < Contact
      class << self
        attr_accessor :client_key, :plugin_id
        attr_accessor :format
      end

      self.format = lambda do |message, priority, category, host|
        text  = "Message: #{message}\n"
        text += "Host: #{host}\n"         if host
        text += "Priority: #{priority}\n" if priority
        text += "Category: #{category}\n" if category
        return text
      end

      attr_accessor :client_key, :plugin_id

      def valid?
        valid = true
        valid &= complain("Attribute 'client_key' must be specified", self) unless arg(:client_key)
        valid &= complain("Attribute 'plugin_id' must be specified", self) unless arg(:plugin_id)
        valid
      end

      def notify(message, time, priority, category, host)
        data = {
          :client_key => arg(:client_key),
          :plugin_id => arg(:plugin_id),
          :format => 'xml',
          'alert[subject]' => message,
          'alert[body]' => Scout.format.call(message, priority, category, host)
        }

        uri = URI.parse('http://scoutapp.com/alerts/create')
        Net::HTTP.post_form(uri, data)

        self.info = "sent scout alert to plugin ##{plugin_id}"
      rescue => e
        applog(nil, :info, "failed to send scout alert to plugin ##{plugin_id}: #{e.message}")
        applog(nil, :debug, e.backtrace.join("\n"))
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
resurrected_god-0.14.0 lib/god/contacts/scout.rb
mcproc-2016.2.20 lib/god/contacts/scout.rb
god-0.13.7 lib/god/contacts/scout.rb
god-0.13.6 lib/god/contacts/scout.rb
god-0.13.5 lib/god/contacts/scout.rb
god-0.13.4 lib/god/contacts/scout.rb
god-0.13.3 lib/god/contacts/scout.rb
god-0.13.2 lib/god/contacts/scout.rb
god-0.13.1 lib/god/contacts/scout.rb
god-0.13.0 lib/god/contacts/scout.rb
god-0.12.1 lib/god/contacts/scout.rb
god-0.12.0 lib/god/contacts/scout.rb
firenxis-god-0.11.0 lib/god/contacts/scout.rb
god-0.11.0 lib/god/contacts/scout.rb