class Pagerduty::EventsApiV1

Trigger incidents via the PagerDuty Events API version 1.

@see v2.developer.pagerduty.com/docs/events-api PagerDuty Events

API V1 documentation

@see Pagerduty.build

@see Pagerduty::EventsApiV1::Incident

Public Class Methods

new(config) click to toggle source

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

@option config [String] integration_key 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.

@option config [String] http_proxy.host The DNS name or IP address of the

proxy host. If nil or unprovided an HTTP proxy will not be used.

@option config [String] http_proxy.port The TCP port to use to access the

proxy.

@option config [String] http_proxy.username username if authorization is

required to use the proxy.

@option config [String] http_proxy.password password if authorization is

required to use the proxy.

@see Pagerduty.build

# File lib/pagerduty/events_api_v1.rb, line 37
def initialize(config)
  @config = config
end

Public Instance Methods

incident(incident_key) click to toggle source

@param [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. The maximum length
is 255 characters.

@return [Pagerduty::EventsApiV1::Incident] The incident referenced by the

key.

@raise [ArgumentError] If incident_key is nil

# 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 = {}) click to toggle source

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

@example Trigger an incident

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

@example 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,
  },
)

@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] 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 [Array] contexts An array of objects. Contexts to be

included with the incident trigger such as links to graphs or images.

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

like included in the incident log.

@return [Pagerduty::EventsApiV1::Incident] The triggered incident.

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

not "success"
# 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