Class: NineOneOne::PagerDutyService

Inherits:
Object
  • Object
show all
Defined in:
lib/nine_one_one/pager_duty_service.rb

Constant Summary collapse

BASE_HOST =
'events.pagerduty.com'.freeze
EVENT_ENDPOINT =
'/generic/2010-04-15/create_event.json'.freeze
THROTTLE_HTTP_STATUS =
403
THROTTLE_RETRIES =
2

Instance Method Summary collapse

Constructor Details

#initialize(api_integration_key) ⇒ PagerDutyService

Returns a new instance of PagerDutyService.



9
10
11
12
# File 'lib/nine_one_one/pager_duty_service.rb', line 9

def initialize(api_integration_key)
  @api_integration_key = api_integration_key
  @http = Http.new(BASE_HOST)
end

Instance Method Details

#trigger_event(incident_key, description, details_hash = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nine_one_one/pager_duty_service.rb', line 14

def trigger_event(incident_key, description, details_hash = nil)
  response = nil

  retry_on(THROTTLE_HTTP_STATUS, THROTTLE_RETRIES) do
    response = make_request(description, details_hash, incident_key)
    response.code.to_i
  end

  # rubocop:disable Style/GuardClause
  unless response.is_a?(Net::HTTPSuccess)
    raise IncidentReportingError, "Failed to create PagerDuty event: #{response.body}"
  end
  # rubocop:enable Style/GuardClause
end