Permalink
Browse files

XMPP plugin

  • Loading branch information...
1 parent 7dd263b commit 827c02bdc943a5a6992ab23edaa3560546804e38 @chamerling chamerling committed Jan 13, 2014
Showing with 98 additions and 1 deletion.
  1. +1 −0 README.md
  2. +3 −1 package.json
  3. +85 −0 plugins/xmpp/xmpp_plugin.js
  4. +9 −0 settings.js
View
@@ -113,6 +113,7 @@ Some plugins are available out-of-the-box:
* Mail
* Twitter
* Webhook
+* XMPP
<img src="http://blog.bazoud.com/images/ssd7a.png" alt="">
View
@@ -46,6 +46,8 @@
"pkginfo": "0.2.3",
"nodemailer": "0.3.28",
"graphite": "0.0.6",
- "request": "2.11.4"
+ "request": "2.11.4",
+ "node-xmpp-client": "0.1.4",
+ "ltx": "0.3.4"
}
}
@@ -0,0 +1,85 @@
+/**
+ * XMPP plugin : Post status to XMPP buddy
+ *
+ * @author Christophe Hamerling - christophe.hamerling@gmail.com
+ */
+var _ = require('underscore')._
+ , log;
+
+exports.create = function(api, settings) {
+
+ log = settings.logger ? settings.logger : require('util').log;
+
+ if (settings.plugins && settings.plugins.xmpp && settings.plugins.xmpp.enable) {
+ log('Creating the plugin: ' + __filename);
+
+ var lastService = {};
+ var lastCount = 0;
+ var XMPP = require('node-xmpp-client');
+ var ltx = require('ltx');
+
+ var client = new XMPP.Client(settings.plugins.xmpp.from);
+
+ var sendXMPP = function(message) {
+ var stanza = new ltx.Element('message', {to: settings.plugins.xmpp.to, type: 'chat'}).c('body').t(message);
+ client.send(stanza);
+ }
+
+ client.on('error', function() {
+ log('Error on XMPP Client');
+ });
+
+ client.on('stanza', function(message) {
+ log("Got a message " + message);
+ });
+
+ client.on('online', function() {
+ api.on('up', function(service) {
+ checkChanges(service);
+ });
+
+ api.on('down', function(service) {
+ checkChanges(service);
+ });
+
+ api.on('unknown', function(service) {
+ checkChanges(service);
+ });
+
+ api.on('critical', function(service) {
+ checkChanges(service);
+ });
+
+ api.on('maintenance', function(service) {
+ checkChanges(service);
+ });
+
+ api.on('refresh', function(status) {
+ var count = status.summarize.up + status.summarize.critical + status.summarize.down + status.summarize.unknown + status.summarize.maintenance;
+ if (lastCount != count) {
+ var msg = 'Up: ' + status.summarize.up + ', ' + 'Critical: ' + status.summarize.critical + ', Down: ' + status.summarize.down + ', Maintenance: ' + status.summarize.maintenance + ', Unknown: ' + status.summarize.unknown;
+ sendXMPP(msg);
+ lastCount = count;
+ }
+ });
+ });
+
+ var checkChanges = function(service) {
+ if (!lastService[service.name]) {
+ lastService[service.name] = {};
+ lastService[service.name].status = 'up';
+ }
+ if (lastService[service.name].status != service.status) {
+ if (service.status == 'up') {
+ sendXMPP("[" + service.status.toUpperCase() + "] " + service.name);
+ } else {
+ sendXMPP("[" + service.status.toUpperCase() + "] " + service.name + ", Code: " + service.statusCode + ", Message: " + service.message);
+ }
+ }
+ lastService[service.name].status = service.status;
+ };
+
+ } else {
+ log('XMPP plugin is not enabled');
+ }
+};
View
@@ -123,6 +123,15 @@ exports.create = function() {
channels: ['#statusdashboard']
}
},
+ xmpp: {
+ enable: true,
+ from: {
+ jid: 'from@jabber.org',
+ password: 'XXX',
+ host : 'jabber.org'
+ },
+ to: 'to@jabber.org'
+ },
twitter: {
enable: false,
consumer_key: "",

0 comments on commit 827c02b

Please sign in to comment.