Skip to content

Instantly share code, notes, and snippets.

@twilson63
Last active August 29, 2015 14:13
Show Gist options
  • Save twilson63/8edffed4944a7c07238a to your computer and use it in GitHub Desktop.
Save twilson63/8edffed4944a7c07238a to your computer and use it in GitHub Desktop.
/**
* Campfire plugin for the uptime project - https://github.com/fzaninotto/uptime
*
* This index.js files goes to a directory `plugins/campfire` in your installation of uptime.
*
* Notifies all events (up, down, paused, restarted) to campfire
*
* This plugin has a dependency on `ranger`.
* Add this to the "dependencies" object in your `package.json` file :
*
* "ranger": "0.2.4"
*
*
* To enable the plugin, call init() from plugins/index.js
* exports.init = function() {
* require('./campfire').init();
* }
*
* Example configuration
*
* campfire:
* room: 1 # Must be the room id, not it's name
* account: uptime
* token: abcd
*
* event:
* up: true
* down: true
* paused: false
* restarted: false
*/
var config = require('config').campfire;
var CheckEvent = require('../../models/checkEvent');
var ranger = require('ranger');
exports.init = function() {
CheckEvent.on('afterInsert', function(checkEvent) {
if (!config.event[checkEvent.message])
return;
checkEvent.findCheck(function(err, check) {
if (err)
return console.error(err);
var message = "[Uptime] The application " + check.name + " just went to status " + checkEvent.message
var room_id = config.room;
var account = config.account;
var token = config.token;
var client = ranger.createClient(account, token);
client.room(room_id, function (room) {
room.speak(message);
});
});
});
console.log('Enabled Campfire notifications');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment