class Backup::Notifier::DataDog

Attributes

aggregation_key[RW]

The aggregation_key for the event

alert_type[RW]

The alert_type of the event (error/warning/info/success)

api_key[RW]

The DataDog API key

date_happened[RW]

The timestamp for the event

host[RW]

The host that generated the event

priority[RW]

The priority of the event (low/normal)

source_type_name[RW]

The source_type for the event (nagios, hudson, jenkins, user, my apps, feed, chef, puppet, git, bitbucket, fabric, capistrano)

tags[RW]

The tags for this host (should be an array)

title[RW]

The title of the event

Public Class Methods

new(model, &block) click to toggle source
Calls superclass method Backup::Notifier::Base::new
# File lib/backup/notifier/datadog.rb, line 47
def initialize(model, &block)
  super
  instance_eval(&block) if block_given?
  @title ||= "Backup #{model.label}"
end

Private Instance Methods

default_alert_type(status) click to toggle source

set alert type

# File lib/backup/notifier/datadog.rb, line 95
def default_alert_type(status)
  case status
  when :success then "success"
  when :warning then "warning"
  when :failure then "error"
  end
end
notify!(status) click to toggle source

Notify the user of the backup operation results.

‘status` indicates one of the following:

‘:success` : The backup completed successfully. : Notification will be sent if `on_success` is `true`.

‘:warning` : The backup completed successfully, but warnings were logged. : Notification will be sent if `on_warning` or `on_success` is `true`.

‘:failure` : The backup operation failed. : Notification will be sent if `on_warning` or `on_success` is `true`.

# File lib/backup/notifier/datadog.rb, line 72
def notify!(status)
  msg = message.call(model, status: status_data_for(status))

  hash = { alert_type: default_alert_type(status) }
  hash.store(:msg_title,        @title)
  hash.store(:date_happened,    @date_happened)    if @date_happened
  hash.store(:priority,         @priority)         if @priority
  hash.store(:host,             @host)             if @host
  hash.store(:tags,             @tags)             if @tags
  hash.store(:aggregation_key,  @aggregation_key)  if @aggregation_key
  hash.store(:source_type_name, @source_type_name) if @source_type_name
  hash.store(:alert_type,       @alert_type)       if @alert_type
  send_event(msg, hash)
end
send_event(msg, hash) click to toggle source

Dogapi::Client will raise an error if unsuccessful.

# File lib/backup/notifier/datadog.rb, line 88
def send_event(msg, hash)
  client = Dogapi::Client.new(@api_key)
  event = Dogapi::Event.new(msg, hash)
  client.emit_event(event)
end