Class: Pagerduty::EventsApiV1

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

Overview

Trigger incidents via the PagerDuty Events API version 1.

Defined Under Namespace

Classes: Incident

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ EventsApiV1

Rather than using this directly, use the Pagerduty.build method to construct an instance.

Parameters:

  • config (Hash)

    a customizable set of options

Options Hash (config):

  • integration_key (String)

    Authentication key for connecting to PagerDuty. A UUID expressed as a 32-digit hexadecimal number. Integration keys are generated by creating a new service, or creating a new integration for an existing service in PagerDuty, and can be found on a service’s Integrations tab. This option is required.

  • http_proxy.host (String)

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

  • http_proxy.port (String)

    The TCP port to use to access the proxy.

  • http_proxy.username (String)

    username if authorization is required to use the proxy.

  • http_proxy.password (String)

    password if authorization is required to use the proxy.

See Also:



37
38
39
# File 'lib/pagerduty/events_api_v1.rb', line 37

def initialize(config)
  @config = config
end

Instance Method Details

#incident(incident_key) ⇒ Pagerduty::EventsApiV1::Incident

Returns The incident referenced by the key.

Parameters:

  • 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. The maximum length is 255 characters.

Returns:

Raises:

  • (ArgumentError)

    If incident_key is nil



113
114
115
116
117
# File 'lib/pagerduty/events_api_v1.rb', line 113

def incident(incident_key)
  raise ArgumentError, "incident_key is nil" if incident_key.nil?

  Incident.new(@config.merge(incident_key: incident_key))
end

#trigger(description, options = {}) ⇒ Pagerduty::EventsApiV1::Incident

Send PagerDuty a trigger event to report a new or ongoing problem.

Examples:

Trigger an incident

incident = pagerduty.trigger(
  "<A description of the event or outage>"
)

Trigger an incident, providing more context and details

incident = pagerduty.trigger(
  "FAILURE for production/HTTP on machine srv01.acme.com",
  client:     "Sample Monitoring Service",
  client_url: "https://monitoring.service.com",
  contexts:   [
    {
      type: "link",
      href: "http://acme.pagerduty.com",
      text: "View the incident on PagerDuty",
    },
    {
      type: "image",
      src:  "https://chart.googleapis.com/chart.png",
    }
  ],
  details:    {
    ping_time: "1500ms",
    load_avg:  0.75,
  },
)

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):

  • 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.

  • contexts (Array)

    An array of objects. Contexts to be included with the incident trigger such as links to graphs or images.

  • details (Hash)

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

Returns:

Raises:



93
94
95
96
97
# File 'lib/pagerduty/events_api_v1.rb', line 93

def trigger(description, options = {})
  config = @config.merge(incident_key: options[:incident_key])
  options = options.reject { |key| key == :incident_key }
  Incident.new(config).trigger(description, options)
end