Created
July 14, 2013 13:49
-
-
Save xphyr/5994345 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great, event without understanding why this code works, it's working perfectly for me, thanks !!