Create a gist now

Instantly share code, notes, and snippets.

Simple Plugin for "Uptime" that send alerts via Pushover. I am not a Node hacker ... I barely understand why this code works .... but it does. I have not tried it with multiple users yet, so dont know if it will work to do multiple notifications. Let me know if you try it.
/**
* Pushover plugin for the uptime project - https://github.com/fzaninotto/uptime
* Thanks to DMathieu for the Campfire plugin which I basically hacked up to make this
* work: https://gist.github.com/dmathieu/5592418
*
* This index.js files goes to a directory `plugins/pushover` in your installation of uptime.
*
* Notifies all events (up, down, paused, restarted) to pushover
*
* This plugin has a dependency on `pushover-notifications`.
* Add this to the "dependencies" object in your `package.json` file :
*
* "pushover-notifications": "0.1.5"
*
*
* To enable the plugin, add the following line to the plugins section of your config file
* plugins:
* - ./plugins/pushover
*
* Example configuration
*
* pushover:
* token: 8973lkhjfdso8y3 # Authentication token from pushover for app
* user: 09r4ljfdso98r # This is the user token you want to send to
*
* event:
* up: true
* down: true
* paused: false
* restarted: false
*/
var config = require('config').pushover;
var CheckEvent = require('../../models/checkEvent');
var pushover = require('pushover-notifications');
exports.initWebApp = function() {
CheckEvent.on('afterInsert', function(checkEvent) {
if (!config.event[checkEvent.message])
return;
checkEvent.findCheck(function(err, check) {
if (err)
return console.error(err);
var msg = {
message: "The application " + check.name + " just went to status " + checkEvent.message,
title: "Uptime Status",
sound: 'magic', // optional
priority: 1 // optional
};
var push = new pushover({
token: config.token
});
push.user = config.user;
push.send( msg, function( err, result ) {
if ( err ) {
throw err;
}
console.log( result );
});
});
});
console.log('Enabled Pushover notifications');
};
@lologhi
lologhi commented Sep 20, 2016

This is great, event without understanding why this code works, it's working perfectly for me, thanks !!

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