All Projects â†’ envato â†’ Pagerduty

envato / Pagerduty

Licence: mit
📟 A Ruby gem for talking to the Pagerduty Events API

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Pagerduty

Lumberyard Cubism3 Gem
An Amazon Lumberyard Gem that adds in Live2D Cubism3 functionality to LyShine.
Stars: ✭ 13 (-86.17%)
Mutual labels:  gem
Colorize
Ruby string class extension. It add some methods to set color, background color and text effect on console easier using ANSI escape sequences.
Stars: ✭ 1,082 (+1051.06%)
Mutual labels:  gem
Bhf
Rails-Engine-Gem that offers an admin interface for trusted user
Stars: ✭ 81 (-13.83%)
Mutual labels:  gem
Lita Line
A Line adapter for Lita
Stars: ✭ 15 (-84.04%)
Mutual labels:  gem
Pig Ci Rails
Monitor your Ruby Applications metrics (Memory, SQL Requests & Request Time) as part of your test suite.
Stars: ✭ 53 (-43.62%)
Mutual labels:  gem
Validated object
Self-validating Ruby objects
Stars: ✭ 57 (-39.36%)
Mutual labels:  gem
Itamae Plugin Resource Encrypted remote file
encrypt secret data (e.g. id_rsa), and forward decrypted file to remote.
Stars: ✭ 10 (-89.36%)
Mutual labels:  gem
Validates formatting of
Common Rails validations wrapped in a gem.
Stars: ✭ 91 (-3.19%)
Mutual labels:  gem
Matchete
A DSL for method overloading in Ruby based on pattern matching
Stars: ✭ 53 (-43.62%)
Mutual labels:  gem
Ansible Role Ruby
Ansible Role - Ruby
Stars: ✭ 77 (-18.09%)
Mutual labels:  gem
Administrate Field Belongs to search
Plugin that adds search capabilities to belongs_to associations for Administrate
Stars: ✭ 29 (-69.15%)
Mutual labels:  gem
Render async
render_async lets you include pages asynchronously with AJAX
Stars: ✭ 974 (+936.17%)
Mutual labels:  gem
Offline geocoder
Offline Geocoder
Stars: ✭ 64 (-31.91%)
Mutual labels:  gem
Sixarm ruby magic number type
SixArm.com » Ruby » MagicNumberType infers a data type from the data's leading bytes
Stars: ✭ 13 (-86.17%)
Mutual labels:  gem
Active reporting
OLAP-like DSL for ActiveRecord-based reporting
Stars: ✭ 83 (-11.7%)
Mutual labels:  gem
Modern Resume Theme
A modern static resume template and theme. Powered by Jekyll and GitHub pages.
Stars: ✭ 868 (+823.4%)
Mutual labels:  gem
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+1056.38%)
Mutual labels:  gem
Graf
A simple git log analyzer gem
Stars: ✭ 94 (+0%)
Mutual labels:  gem
Pager Api
Easy API pagination for Rails
Stars: ✭ 86 (-8.51%)
Mutual labels:  gem
Tabler Rubygem
Rubygem for https://tabler.github.io
Stars: ✭ 77 (-18.09%)
Mutual labels:  gem

pagerduty

License MIT Gem Version Gem Downloads Build Status

Provides a lightweight Ruby interface for calling the PagerDuty Events API.

Installation

Add this line to your application's Gemfile:

gem 'pagerduty'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pagerduty

Usage

First, obtain an Events API integration key from PagerDuty. Follow the instructions in PagerDuty's documentation to procure one.

Events API V2

# Instantiate a Pagerduty service object providing an integration key and the
# desired API version: 2
pagerduty = Pagerduty.build(
  integration_key: "<integration-key>",
  api_version:     2
)

# Trigger an incident providing minimal details
incident = pagerduty.trigger(
  summary:  "summary",
  source:   "source",
  severity: "critical"
)

# Trigger an incident providing full context
incident = pagerduty.trigger(
  summary:        "Example alert on host1.example.com",
  source:         "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003",
  severity:       %w[critical error warning info].sample,
  timestamp:      Time.now,
  component:      "postgres",
  group:          "prod-datapipe",
  class:          "deploy",
  custom_details: {
                    ping_time: "1500ms",
                    load_avg:  0.75
                  },
  images:         [
                    {
                      src:  "https://www.pagerduty.com/wp-content/uploads/2016/05/pagerduty-logo-green.png",
                      href: "https://example.com/",
                      alt:  "Example text",
                    },
                  ],
  links:          [
                    {
                      href: "https://example.com/",
                      text: "Link text",
                    },
                  ],
  client:         "Sample Monitoring Service",
  client_url:     "https://monitoring.example.com"
)

# Acknowledge and/or resolve the incident
incident.acknowledge
incident.resolve

# Provide a client-defined incident key
# (this can be used to update existing incidents)
incident = pagerduty.incident("<incident-key>")
incident.trigger(
  summary:  "summary",
  source:   "source",
  severity: "critical"
)
incident.acknowledge
incident.resolve

See the PagerDuty Events API V2 documentation for a detailed description on the parameters you can send when triggering an incident.

Events API V1

The following code snippet shows how to use the Pagerduty Events API version 1.

# Instantiate a Pagerduty with a service integration key
pagerduty = Pagerduty.build(
  integration_key: "<integration-key>",
  api_version:     1,
)

# Trigger an incident
incident = pagerduty.trigger(
  "FAILURE for production/HTTP on machine srv01.acme.com",
)

# Trigger an incident providing 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?chs=600x400&chd=t:6,2,9,5,2,5,7,4,8,2,1&cht=lc&chds=a&chxt=y&chm=D,0033FF,0,0,5,1",
    }
  ],
  details:    {
    ping_time: "1500ms",
    load_avg:  0.75,
  },
)

# Acknowledge the incident
incident.acknowledge

# Acknowledge, providing a description and extra details
incident.acknowledge(
  "Engineers are investigating the incident",
  {
    ping_time: "1700ms",
    load_avg:  0.71,
  }
)

# Resolve the incident
incident.resolve

# Resolve, providing a description and extra details
incident.acknowledge(
  "A fix has been deployed and the service has recovered",
  {
    ping_time: "120ms",
    load_avg:  0.23,
  }
)

# Provide a client defined incident key
# (this can be used to update existing incidents)
incident = pagerduty.incident("<incident-key>")
incident.trigger("Description of the event")
incident.acknowledge
incident.resolve

See the PagerDuty Events API V1 documentation for a detailed description of the parameters you can send when triggering an incident.

HTTP Proxy Support

One can explicitly define an HTTP proxy like this:

pagerduty = Pagerduty.build(
  integration_key: "<integration-key>",
  api_version:     2, # The HTTP proxy settings work with either API version
  http_proxy:      {
    host:     "my.http.proxy.local",
    port:     3128,
    username: "<my-proxy-username>",
    password: "<my-proxy-password>",
  }
)

# Subsequent API calls will then be sent via the HTTP proxy
incident = pagerduty.trigger(
  summary:  "summary",
  source:   "source",
  severity: "critical"
)

Debugging Error Responses

The gem doesn't encapsulate HTTP error responses from PagerDuty. Here's how to go about debugging these unhappy cases:

begin
  pagerduty.trigger(
    summary:  "summary",
    source:   "source",
    severity: "critical"
  )
rescue Net::HTTPClientException => error
  error.response.code    #=> "400"
  error.response.message #=> "Bad Request"
  error.response.body    #=> "{\"status\":\"invalid event\",\"message\":\"Event object is invalid\",\"errors\":[\"Service key is the wrong length (should be 32 characters)\"]}"
end

Legacy Interface

The older Ruby interface from version 2 of the gem is still available. However, this is deprecated and will be removed in the next major release.

# Instantiate a Pagerduty with your specific service key
pagerduty = Pagerduty.new("<my-integration-key>")

# Trigger an incident
incident = pagerduty.trigger("incident description")

# Acknowledge and resolve the incident
incident.acknowledge
incident.resolve

Contributing

  1. Fork it ( https://github.com/envato/pagerduty/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].