Skip to content
Browse files

[ping, gitignore] initial, improved gitignore

  • Loading branch information...
1 parent 228565a commit 73b493b5508c6059768dd69c1f8ef71c23d41aa2 @indutny indutny committed Jun 29, 2011
Showing with 81 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +8 −0 config.json.defaults
  3. +68 −0 lib/plugins/ping.js
  4. 0 logs/.keep
View
5 .gitignore
@@ -1 +1,6 @@
config.json
+node_modules
+node_modules/*
+npm-debug.log
+logs/*
+!logs/.keep
View
8 config.json.defaults
@@ -16,6 +16,14 @@
"%% actually looks rather nice today."
],
"plugins": {
+ "ping": {
+ "interval": 30000,
+ "urls": {
+ "http://www.nodejitsu.com/",
+ "http://blog.nodejitsu.com/"
+ },
+ "failMessage": "Oops! Bad news here, guys!"
+ },
"twitter": {
"filter" : 25,
"track": [
View
68 lib/plugins/ping.js
@@ -0,0 +1,68 @@
+// plugin for getting realtime health
+
+var async = require('async'),
+ http = require('http'),
+ url = require('url');
+
+var Ping = function Ping() {
+};
+
+Ping.prototype.start = function(client, config) {
+ if (!config.plugins.ping || !config.plugins.ping.urls) {
+ console.log('config.plgins.ping.urls should be defined');
+ return;
+ }
+
+ var that = this;
+
+ this.client = client;
+ this.channel = '';
+ this.urls = config.plugins.ping.urls;
+ this.failMessage = config.plugins.ping.failMessage ||
+ 'Oops! Bad news here, guys!';
+
+ client.once('join', function(channel, nick) {
+ that.channel = channel;
+
+ that.tick();
+ that.interval = setInterval(that.tick.bind(that),
+ config.plugins.ping.interval || 60000);
+
+ });
+};
+
+Ping.prototype.tick = function() {
+ var that = this,
+ client = this.client,
+ channel = this.channel;
+
+ async.map(this.urls, function(uri, callback) {
+ http.get(url.parse(uri), function(res) {
+ if (res.statusCode < 200 || res.statusCode >= 400) {
+ return err();
+ }
+ }).on('error', function() {
+ err();
+ });
+
+ function err() {
+ callback(uri + ' fails to load!');
+ };
+ }, function(err) {
+ if (err) {
+ client.say(channel,
+ that.failMessage + ' ' +
+ (Array.isArray(err) ?
+ err.join(' ')
+ :
+ err)
+ );
+ }
+ });
+};
+
+Ping.prototype.destroy = function() {
+ clearInterval(this.interval);
+};
+
+module.exports = new Ping();
View
0 logs/.keep
No changes.

0 comments on commit 73b493b

Please sign in to comment.
Something went wrong with that request. Please try again.