class Pagerduty

Constants

VERSION

Attributes

service_key[R]

Public Class Methods

new(service_key, options = {}) click to toggle source

@param [String] #service_key The GUID of one of your “Generic API” services.

This is the "service key" listed on a Generic API's service detail page.

@option options [String] :proxy_host The DNS name or IP address of the

proxy host. If nil or unprovided a proxy will not be used.

@option options [String] :proxy_port The port to use to access the proxy.

@option options [String] :proxy_username username if authorization is

required to use the proxy.

@option options [String] :proxy_password password if authorization is

required to use the proxy.
# File lib/pagerduty.rb, line 31
def initialize(service_key, options = {})
  @service_key = service_key
  @transport = transport_from_options(options)
end

Public Instance Methods

get_incident(incident_key) click to toggle source

@param [String] incident_key The unique identifier for the incident.

@return [PagerdutyIncident] The incident referenced by the key.

@raise [ArgumentError] If incident_key is nil

# File lib/pagerduty.rb, line 85
def get_incident(incident_key)
  fail ArgumentError, "incident_key is nil" if incident_key.nil?
  PagerdutyIncident.new(
    service_key,
    incident_key,
    transport: @transport,
  )
end
trigger(description, options = {}) click to toggle source

Send PagerDuty a trigger event to report a new or ongoing problem. When PagerDuty receives a trigger event, it will either open a new incident, or add a new trigger log entry to an existing incident, depending on the provided incident_key.

@param [String] description A short description of the problem that led to

this trigger. This field (or a truncated version) will be used when
generating phone calls, SMS messages and alert emails. It will also appear
on the incidents tables in the PagerDuty UI. The maximum length is 1024
characters.

@option options [String] :incident_key Identifies the incident to which

this trigger event should be applied. If there's no open (i.e. unresolved)
incident with this key, a new one will be created. If there's already an
open incident with a matching key, this event will be appended to that
incident's log. The event key provides an easy way to "de-dup" problem
reports. If this field isn't provided, PagerDuty will automatically open a
new incident with a unique key.

@option options [String] :client The name of the monitoring client that is

triggering this event.

@option options [String] :client_url The URL of the monitoring client that

is triggering this event.

@option options [Hash] :details An arbitrary hash containing any data you'd

like included in the incident log.

@return [PagerdutyIncident] The triggered incident.

@raise [PagerdutyException] If PagerDuty responds with a status that is not

"success"
# File lib/pagerduty.rb, line 69
def trigger(description, options = {})
  resp = api_call("trigger", options.merge(description: description))
  ensure_success(resp)
  PagerdutyIncident.new(
    service_key,
    resp["incident_key"],
    transport: @transport,
  )
end

Protected Instance Methods

api_call(event_type, args) click to toggle source
# File lib/pagerduty.rb, line 96
def api_call(event_type, args)
  args = args.merge(
    service_key: service_key,
    event_type: event_type,
  )
  @transport.send_payload(args)
end
ensure_success(response) click to toggle source
# File lib/pagerduty.rb, line 104
def ensure_success(response)
  unless response["status"] == "success"
    fail PagerdutyException.new(self, response, response["message"])
  end
end

Private Instance Methods

transport_from_options(options = {}) click to toggle source

@api private

# File lib/pagerduty.rb, line 113
def transport_from_options(options = {})
  options[:transport] || Pagerduty::HttpTransport.new(options)
end