Skip to content

Instantly share code, notes, and snippets.

@qawemlilo
Last active January 29, 2023 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qawemlilo/f650d06035d77c74d5b850167122a3fb to your computer and use it in GitHub Desktop.
Save qawemlilo/f650d06035d77c74d5b850167122a3fb to your computer and use it in GitHub Desktop.
Ideas on how to integrate notification channels with ping-monitor
const Monitor = require('ping-monitor');

// how to get channels
const Mailer = require('@ping-monitor/email');
const Slakey = require('@ping-monitor/slack');
const TwiT = require('@ping-monitor/twitter');
const SMS = require('@ping-monitor/sms');


// channel example
class Channel {

  constructor(options) {
    /*** 
    
      do something with the options
      e.g.
      
      const transporter = require("nodemailer").createTransport(options);
      
      this.transporter = transporter;
      
      this.transporter then becomes accessible within your methods
      
     ***/
  }
  
  up(res, state) {
    // send up notification
  }
  
  down(res, state) {
    // send down notification
  }
  
  stop(res, state) {
    // send stopped notification
  }
  
  error(error, res) {
    // send error notification
  }
  
  timeout(error, res) {
    // send timeout notification
  }
}


let email =  new Mailer({
    host: process.env.MAILER_HOST,
    port: process.env.MAILER_PORT,
    secure: false, 
    auth: {
      user: process.env.MAILER_USER, 
      pass: process.env.MAILER_PASS, 
    },
})

let slack =  new Slakey({
    token: process.env.SLACK_TOKEN;
})

const myMonitor = new Monitor({
    website: 'https://ragingflame.co.za',
    title: 'Raging Flame',
    interval: 10 
});


// option 1
myMonitor.addChannel(email)
myMonitor.addChannel(slack)


// option 2
myMonitor.addSubscriber(email)
myMonitor.addSubscriber(slack)


// option 3
myMonitor.subscribe(email)
myMonitor.subscribe(slack)
@qawemlilo
Copy link
Author

@kailashvele Thanks for your feedback.

  1. Yes I agree, we need more options to make if fully customisable.
  2. The slack snippet was just an example, will have to look at how the api package works.
  3. Yes, will explore how to provide those options.
  4. This was just an example. We could integrate something like Vonage.

I will create a new branch to run some experiments to see what's possible. Will tag you on it.

@kailashvele
Copy link

@qawemlilo Sure I will take a look at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment