class Backup::Notifier::PagerDuty
Attributes
resolve_on_warning[RW]
Determines if a backup with a warning should resolve an incident rather than trigger one.
Defaults to false.
service_key[RW]
PagerDuty Service API Key. Should be a 32 character hex string.
Public Class Methods
new(mode, &block)
click to toggle source
Calls superclass method
Backup::Notifier::Base.new
# File lib/backup/notifier/pagerduty.rb, line 18 def initialize(mode, &block) super instance_eval(&block) if block_given? @resolve_on_warning ||= false end
Private Instance Methods
notify!(status)
click to toggle source
Trigger or resolve a PagerDuty incident for this model
`status` indicates one of the following:
`:success` : The backup completed successfully. : The incident will be resolved if `on_success` is `true`.
`:warning` : The backup completed successfully, but warnings were logged. : An incident will be triggered if `on_warning` or `on_success` is `true`.
`:failure` : The backup operation failed. : An incident will be triggered if `on_failure` is `true`.
# File lib/backup/notifier/pagerduty.rb, line 44 def notify!(status) incident_description = "Backup - #{model.label}" incident_key = "backup/#{model.trigger}" incident_details = { :incident_key => incident_key, :details => { :trigger => model.trigger, :label => model.label, :started_at => model.started_at, :finished_at => model.finished_at, :duration => model.duration, :status => status, :exception => model.exception } } event_type = case status when :success then :resolve when :warning then resolve_on_warning ? :resolve : :trigger when :failure then :trigger end case event_type when :trigger pagerduty.trigger(incident_description, incident_details) when :resolve incident = pagerduty.get_incident(incident_key) incident.resolve(incident_description, incident_details) end end
pagerduty()
click to toggle source
# File lib/backup/notifier/pagerduty.rb, line 75 def pagerduty @pagerduty ||= Pagerduty.new(service_key) end