• Stars
    star
    99
  • Rank 342,503 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 14 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📟 A Ruby gem for talking to the Pagerduty Events API

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

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

More Repositories

1

double_entry

A double-entry accounting system for Ruby applications.
Ruby
417
star
2

envato-wordpress-toolkit

Wordpress toolkit for authors of items available from the Envato Market sites.
PHP
373
star
3

wp-envato-market

WordPress Theme & Plugin management for the Envato Market.
PHP
340
star
4

zxcvbn-ruby

Ruby port of Dropbox's zxcvbn javascript lib
Ruby
314
star
5

stack_master

The missing CloudFormation tool
Ruby
290
star
6

envato-theme-check

The WordPress Theme Check plugin for Envato
PHP
205
star
7

aldous

Brave New World for Rails with more cohesion, less coupling and greater development speed for all
Ruby
128
star
8

event_sourcery

A library for building event sourced applications in Ruby
Ruby
84
star
9

safe_shell

Safely execute shell commands and get their output.
Ruby
74
star
10

react-breakpoints

Respond to changes in a DOM element's size. With React Breakpoints, element queries are no longer "web design's unicorn" 🦄
TypeScript
72
star
11

envato-wordpress-toolkit-library

WordPress Toolkit Library for Envato Marketplace hosted items
PHP
71
star
12

lumberg

Ruby library for the WHM & cPanel API; It's not a half day or anything like that.
Ruby
56
star
13

rails_4_session_flash_backport

Rails 4 Session Flash Backport
Ruby
52
star
14

ami-spec

Acceptance testing your AMIs
Ruby
50
star
15

heroku-deploy

Complete zero downtime deploys for Rails applications on Heroku
Ruby
41
star
16

rack-ecg

Health check page as Rack middleware
Ruby
39
star
17

splinter

Chop your specs in half with Splinter, a collection of helpers to submit forms with RSpec and Capybara.
Ruby
30
star
18

extensions-sketch-plugin

Envato Elements - Sketch Plugin (Beta)
JavaScript
26
star
19

unwrappr

🍫 bundle update PRs: Automated. Annotated. Announced daily.
Ruby
26
star
20

exiv2

A simple wrapper around exiv2
Ruby
25
star
21

jwt_signed_request

Request signing and verification made easy
Ruby
24
star
22

iodized

Iodine rich feature toggling. Lack of iodine can lead to development delays, and stunted growth.
Elixir
21
star
23

react-ab-experiment

A/B Experiment React Component
JavaScript
18
star
24

event_sourcery_todo_app

Example event_sourcery app
Ruby
15
star
25

awsraw

Minimal AWS client
Ruby
14
star
26

moo_moo

Implements OpenSRS XML API
Ruby
14
star
27

create-react-icon

Convert one or multiple svg files into React component
JavaScript
13
star
28

aspect_ratio

Image aspect ratio calculation utility
Ruby
13
star
29

event_sourcery-postgres

Postgres event store implementation for EventSourcery
Ruby
13
star
30

github-pull-request-buildkite-plugin

Open Github pull requests via your Buildkite builds
Shell
13
star
31

cookie-consent

Some helper functions to deal with cookie-consent
TypeScript
11
star
32

knuckle_cluster

Gem to interrogate and connect to ECS clusters, Spot fleets and Autoscaling groups
Ruby
10
star
33

cloudformation_rspec

Test your CloudFormation templates
Ruby
10
star
34

aws-account-concierge

Opensource AWS account management tool
Ruby
9
star
35

flv

FLV Parser
Ruby
9
star
36

ejsonkms

Integrates EJSON with AWS KMS
Go
9
star
37

subvalid

Subjective validation for Plain Old Ruby Objects
Ruby
8
star
38

forked

Forked manages long running worker processes
Ruby
8
star
39

react-resize-observer-hook

Observe multiple DOM elements with a single ResizeObserver.
TypeScript
8
star
40

heroku-buildpack-libsodium

libsodium/rbnacl buildpack for Heroku
Shell
8
star
41

foundation-design-system-tokens

Design Tokens for the Foundation Design System
JavaScript
8
star
42

guide

Document your application with a living component library and styleguide
Ruby
8
star
43

studio-client-uploader

JavaScript
8
star
44

outatime

Choose versioned S3 files from a point in time.
Ruby
7
star
45

wp-image-size-limit

Wordpress plugin for limiting the image file size
PHP
7
star
46

aws-s3-sync-buildkite-plugin

Shell
7
star
47

rails_session_key_rotator

Graceful secret key rotation for the signed cookie store in Rails.
Ruby
6
star
48

babushka-deps

Ruby
6
star
49

lambda-deploy-buildkite-plugin

A Buildkite plugin to deploy AWS Lambda function code
Shell
6
star
50

double_entry-reporting

Reporting on Double Entry accounts and transfers
Ruby
6
star
51

medusa

The most beautiful parallel build system, evar.
JavaScript
5
star
52

hamburglar

Hamburglar helps you prevent fraudulent orders
Ruby
5
star
53

fake_aws

Ruby
5
star
54

market-api-gateway-js

JavaScript SDK for marketplace api-gateway
JavaScript
5
star
55

ejson_wrapper

Combines EJSON with AWS KMS
Ruby
5
star
56

bundle-update-buildkite-plugin

Update Ruby gem dependencies in a Buildkite build!
Shell
5
star
57

stop-the-line-buildkite-plugin

Stop Buildkite pipelines based on build meta-data values.
Shell
5
star
58

encapsulate_as_money

Surprise me ;)
Ruby
5
star
59

event_sourcery_generators

An opinionated CLI tool for building event-sourced Ruby services with EventSourcery
Ruby
4
star
60

imageresize

Image resizing for Envato Sites author tools
Go
4
star
61

react-ab-experiment-example

React AB Experiment example app
JavaScript
4
star
62

packer-ami-copy-buildkite-plugin

A buildkite plugin which simplifies the process of building and copying an AMI with packer
Shell
4
star
63

create-datadog-event-buildkite-plugin

An experimental Buildkite plugin which creates Datadog events.
Shell
4
star
64

heroku-container-deploy-buildkite-plugin

Deploy pre-built docker images to Heroku using Heroku Container Registry
Shell
4
star
65

barricade

better locking
Ruby
4
star
66

google-analytics-for-wordpress

WordPress.org Plugin Mirror
PHP
4
star
67

build-failed-notify-slack-buildkite-plugin

@'s the creator of the failed build via a mapping file
Shell
4
star
68

browser-privacy-checker

Handy React 🎣 module to check whether can use user cookie and similar technologies from browser
TypeScript
4
star
69

unwrappr-demo

Demonstrating the power of Unwrappr
Ruby
3
star
70

marketplace-stats-as-a-service

A little micro service to cache and expose Envato Marketplace stats(total items and total users)
JavaScript
3
star
71

docker-cache-buildkite-plugin

Build a multi-stage compatible cache image and store it in S3
Shell
3
star
72

puppet-hubot

Puppet
3
star
73

sprockets-resilience

Stop Rails from killing your site when assets aren't precompiled
Ruby
3
star
74

rack_fake_s3

Ruby
3
star
75

mandrill-merge

We all hate spam, but sometimes you need to get an important message out to a large group of people. Mandrill is great at allowing you to define templates, sending emails out, and keeping track of sends and responses. But how do you get the data from your database over to Mandrill quickly and easily? That's where MandrillMerge comes in...
Ruby
3
star
76

chisel-scripts

Chisel scripts created to debug any issues
Lua
2
star
77

siren-call

A gem for interacting with Siren style REST APIs
Ruby
2
star
78

backbone.proxy-view

A proxy view is an instance of Backbone.View that doesn't render any of its own HTML
CoffeeScript
2
star
79

iodized_ruby_client

Ruby
2
star
80

eventory

A new take on event sourcing in ruby
Ruby
2
star
81

docker-size-annotation-buildkite-plugin

Annotates the build with a docker image size
Shell
2
star
82

thrift-erlang

copy + paste of Apache thrift erlang lib. Mirrored here so it can be used for rebar/mix etc
Erlang
2
star
83

fancy-confluence

CSS
2
star
84

spot_build

Agents are transient, Jobs are forever
Ruby
2
star
85

logstash-filter-dynamo_enrich

Enrich Logstash events with data from DynamoDB
Ruby
2
star
86

batch_retry

Batch send data with retries and exponential backoff
Python
2
star
87

rack_request_ip_strategies

Replacement for Rack::Request#ip
Ruby
2
star
88

heartbeat

Heartbeat plugin that exposes an API to monitor internal services
Ruby
2
star
89

wordpress-https

A fork of an older version of wordpress-https plugin that disables some super-slow functionality.
PHP
2
star
90

ejson2env-buildkite-plugin

A Buildkite plugin for exporting environment variables stored in ejson files using ejson2env
Shell
2
star
91

backbone.autocomplete-view

A template driven autocomplete view for Backbone
CoffeeScript
2
star
92

swarm

Ruby
2
star
93

cloudformation-output-buildkite-plugin

Collects cloudformation output from an AWS stack and add them as environment variables
Shell
2
star
94

studio-asset-service-uploader

An uploader for the studio asset service
JavaScript
1
star
95

puppet_module_provider

Ruby
1
star
96

babel-plugin-postcss-cssmodules-transform

Babel Plugin Transform PostCSS and extract static CSS
JavaScript
1
star
97

studio-asset-service-client-js

A javascript client for the studio asset service
JavaScript
1
star
98

reproduce-fluentd-cascading-buffer

Reproduce cascading failure when Fluentd's internal memory buffer becomes full
Shell
1
star
99

virtellus

A smaller, faster, less powerful Virtus
Ruby
1
star
100

auth0-logs-to-s3

JavaScript
1
star