Class: NineOneOne::PagerDutyService
- Inherits:
-
Object
- Object
- NineOneOne::PagerDutyService
- Defined in:
- lib/nine_one_one/pager_duty_service.rb
Constant Summary collapse
- BASE_HOST =
'events.pagerduty.com'.freeze
- EVENTS_API_V2_ENDPOINT =
'/v2/enqueue'.freeze
- THROTTLE_HTTP_STATUS =
403
- THROTTLE_RETRIES =
2
- HIGH_URGENCY_ERROR =
'error'.freeze
- LOW_URGENCY_ERROR =
'warning'.freeze
Instance Method Summary collapse
-
#initialize(api_integration_key) ⇒ PagerDutyService
constructor
A new instance of PagerDutyService.
- #trigger_event(description, source: Socket.gethostname, dedup_key: nil, severity: HIGH_URGENCY_ERROR, details_hash: nil) ⇒ Object
Constructor Details
#initialize(api_integration_key) ⇒ PagerDutyService
Returns a new instance of PagerDutyService.
10 11 12 13 |
# File 'lib/nine_one_one/pager_duty_service.rb', line 10 def initialize(api_integration_key) @api_integration_key = api_integration_key @http = Http.new(BASE_HOST) end |
Instance Method Details
#trigger_event(description, source: Socket.gethostname, dedup_key: nil, severity: HIGH_URGENCY_ERROR, details_hash: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nine_one_one/pager_duty_service.rb', line 15 def trigger_event(description, source: Socket.gethostname, dedup_key: nil, severity: HIGH_URGENCY_ERROR, details_hash: nil) response = nil retry_on(THROTTLE_HTTP_STATUS, THROTTLE_RETRIES) do body = request_body(description, source, dedup_key, severity, details_hash) response = make_request(body) 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 |