npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pagerduty-plus

v0.0.2

Published

wrapper for node pagerduty library that adds throttling and some other features

Downloads

6

Readme

pagerduty-plus Build Status

a wrapper for nodejs pagerduty moddule that adds throttling, filtering and automatic incident resolution

var Alerter = require('pagerduty-plus') ;
var alerter = new Alerter({
  serviceKeys: ['service-key1', 'service-key2'], 
  events: [
    {
      name: 'DNS-FAILED',
      description: 'unable to resolve hostname'
    },
    {
      name: 'DNS-SUCCESS',
      description: 'successfully resolved hostname',
      resolves: 'DNS-FAILED',
      notify: false
    }        
  ]
}) ;

alerter.alert('DNS-FAILED') ; // sends two pager duty alerts

//time passes...

alerter.alert('DNS-SUCCESS'); // resolves the two incidents

Constructor

Most of the configuration happens when the Alerter object is constructed, via the arguments passed. In the simplest possible implementation, you need only pass an object with a 'serviceKeys' property, which should be an array of one or more pagerduty service keys:

Simple constructor

var Alerter = require('pagerduty-plus') ;
var alerter = new Alerter({
  serviceKeys: ['myservice-key']
}) ;

alerter.alert('something went wrong..', { details: {...} } ) ;

More complex scenarios

Of course, you don't gain much from simply using the underlying pagerduty module in this case: the code above simply creates a pager duty incident with the string provided as the description and whatever additional details you provide.

To get the benefits of throttling, etc, you need to provide some information about the events you will triggering alerts on. For instance, in the first example above, we configured two events ('DNS-FAILED' and 'DNS-SUCCESS'), and indicated they are related in that an occurrence of one event should resolve a previous occurrence of the other.

Filtering recipients based on severity

Similarly, we can assign events severity levels, and have the alerts sent to different groups depending on severity. Severity levels are represented by non-negative integer values, with higher values representing more severe events. When configuring service keys, you can associate a level with a service key, in which case it will receive an alert for any event with a severity greater than or equal to that level. If you configure a service key with no associated level, it receives all alerts.

var Alerter = require('pagerduty-plus') ;
var alerter = new Alerter({
  serviceKeys: ['my-service-key', 
    {level: 3, keys: 'your-sevice-key2'}, 
    {level: 8, keys: ['customer-service-key1', 'customer-service-key2']}
  ], 
  events: [
    {
      name: 'SYSTEM-DOWN',
      description: 'system is down or unresponsive',
      level: 10
    },
    {
      name: 'SERVICE-DEGRADED',
      description: 'system is working but slowly',
      level: 5
    },
    {
      name: 'INFORMATIONAL-EVENT',
      description: 'something of interest happened, but I don\'t want to worry you...',
      level: 1
    }        
  ]
}) ;
alerter.alert('SYSTEM-DOWN');              // everyone gets this

alerter.alert('SERVICE-DEGRADED');         // you and I get this; customer doesn't

alerter.alert('INFORMATIONAL-ALERT');      // only I get this..

Automatically resolving pagerduty incidents

This was mentioned above, but let's go into a bit more detail. Often, you may have "bookend" type of events, where the occurrence of one event signifies the start of a problem, and a later occurrence of another event signifies the problem has been resolved -- think: "I lost my database connection" and "I regained my database connection".

When you have these bookend type of events, you can automatically cause an incident that has been opened to be automatically resolved with the paired event occurs. In order to do so, you need to use the 'resolves' property of when defining the event that resolves an incident opened by the other event. So, as in the database connection example, you would define:

var Alerter = require('pagerduty-plus') ;
var alerter = new Alerter({
  serviceKeys: [...], 
  events: [
    {
      name: 'db-connection-lost',
      description: 'lost connection to database'
    },
    {
      name: 'db-connection-established',
      description: 'gained connection to database',
      resolves: 'db-connection-lost'
    }        
  ]
}) ;

Then, when a 'database-connection-gained' event is recorded, it will automatically close the pagerduty incident opened if an earlier 'db-connection-lost' event was recorded.

alerter.alert('db-connection-lost');          // incident created on pagerduty

alerter.alert('db-connection-established');   // incident resolved on pagerduty

However, imagine that you have two databases that you are monitoring. You need to make sure that the the lost/re-gained pairs of events "match", in the sense of applying to the same database. In that use case, you would supply a 'target' property in the object passed to Alerter#alert to identify which database instance the event pertains to. The value for target can be anything you want, as long as it identifies the resource about which the event is being generated.

var Alerter = require('pagerduty-plus') ;
var alerter = new Alerter({
  serviceKeys: [...], 
  events: [
    {
      name: 'db-connection-lost',
      description: 'lost connection to database'
    },
    {
      name: 'db-connection-established',
      description: 'gained connection to database',
      resolves: 'db-connection-lost'
    }        
  ]
}) ;

alerter.alert('db-connection-lost', {target: 'database-url-1'}); //lost connection to database 1

alerter.alert('db-connection-lost', {target: 'database-url-2'}); //lost connection to database 2

alerter.alert('db-connection-established', {target: 'database-url-1'}); //incident for db 1 resolved; incident for db2 stays open

API

API documentation can be found here.