Class: Pagerduty

Inherits:
Object
  • Object
show all
Defined in:
lib/pagerduty.rb,
lib/pagerduty/version.rb,
lib/pagerduty/http_transport.rb

Direct Known Subclasses

PagerdutyIncident

Defined Under Namespace

Classes: HttpTransport

Constant Summary collapse

VERSION =
"2.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_key, options = {}) ⇒ Pagerduty

Returns a new instance of Pagerduty

Parameters:

  • service_key (String)

    The GUID of one of your “Generic API” services. This is the “service key” listed on a Generic API's service detail page.

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

    a customizable set of options

Options Hash (options):

  • :proxy_host (String)

    The DNS name or IP address of the proxy host. If nil or unprovided a proxy will not be used.

  • :proxy_port (String)

    The port to use to access the proxy.

  • :proxy_username (String)

    username if authorization is required to use the proxy.

  • :proxy_password (String)

    password if authorization is required to use the proxy.


31
32
33
34
# File 'lib/pagerduty.rb', line 31

def initialize(service_key, options = {})
  @service_key = service_key
  @transport = transport_from_options(options)
end

Instance Attribute Details

#service_keyObject (readonly)

Returns the value of attribute service_key


15
16
17
# File 'lib/pagerduty.rb', line 15

def service_key
  @service_key
end

Instance Method Details

#get_incident(incident_key) ⇒ PagerdutyIncident

Returns The incident referenced by the key.

Parameters:

  • incident_key (String)

    The unique identifier for the incident.

Returns:

Raises:

  • (ArgumentError)

    If incident_key is nil


85
86
87
88
89
90
91
92
# 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 = {}) ⇒ PagerdutyIncident

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.

Parameters:

  • description (String)

    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.

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

    a customizable set of options

Options Hash (options):

  • :incident_key (String)

    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.

  • :client (String)

    The name of the monitoring client that is triggering this event.

  • :client_url (String)

    The URL of the monitoring client that is triggering this event.

  • :details (Hash)

    An arbitrary hash containing any data you'd like included in the incident log.

Returns:

Raises:


69
70
71
72
73
74
75
76
77
# 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