Class: Minicron::PagerDuty

Inherits:
Object
  • Object
show all
Defined in:
lib/minicron/alert/pagerduty.rb

Overview

Allows the sending of pagerduty alerts

Instance Method Summary collapse

Constructor Details

#initializePagerDuty

Used to set up on the pagerduty client


7
8
9
10
# File 'lib/minicron/alert/pagerduty.rb', line 7

def initialize
  # Get an instance of the Pagerduty client
  @client = ::Pagerduty.new(Minicron.config['alerts']['pagerduty']['service_key'])
end

Instance Method Details

#get_message(options = {}) ⇒ Object

Return the message for an alert

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • job (Minicron::Hub::Job)

    a job instance

  • kind (String)

    'fail' or 'miss'

  • schedule_id (Integer, nil)

    only applies to 'miss' alerts

  • execution_id (Integer, nil)

    only used by 'fail' alerts

  • job_id (Integer)

    used to look up the job name for the alert message

  • expected_at (Time)

    when the schedule was expected to execute

  • medium (String)

    the medium to send the alert via


21
22
23
24
25
26
27
28
29
30
# File 'lib/minicron/alert/pagerduty.rb', line 21

def get_message(options = {})
  case options[:kind]
  when 'miss'
    "Job ##{options[:job_id]} failed to execute at its expected time - #{options[:expected_at]}"
  when 'fail'
    "Execution ##{options[:execution_id]} of Job ##{options[:job_id]} failed"
  else
    fail Exception, "The kind '#{options[:kind]} is not supported!"
  end
end

#send(title, message) ⇒ Object

Send a pager duty alert

Parameters:

  • title (String)
  • message (String)

36
37
38
# File 'lib/minicron/alert/pagerduty.rb', line 36

def send(title, message)
  @client.trigger(title, :message => message)
end