Class: Pagerduty

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

Direct Known Subclasses

PagerdutyIncident

Defined Under Namespace

Modules: HttpTransport

Constant Summary collapse

VERSION =
"2.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_key) ⇒ 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.



21
22
23
# File 'lib/pagerduty.rb', line 21

def initialize(service_key)
  @service_key = service_key
end

Instance Attribute Details

#service_keyObject (readonly)

Returns the value of attribute service_key.



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

def service_key
  @service_key
end

Instance Method Details

#get_incident(incident_key) ⇒ PagerdutyIncident

Returns The incident referenced by the key.

Returns:



66
67
68
# File 'lib/pagerduty.rb', line 66

def get_incident(incident_key)
  PagerdutyIncident.new service_key, incident_key
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:



58
59
60
61
62
# File 'lib/pagerduty.rb', line 58

def trigger(description, options = {})
  resp = api_call("trigger", options.merge(:description => description))
  ensure_success(resp)
  PagerdutyIncident.new service_key, resp["incident_key"]
end