This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '325bb1915dc9f606eff5d3a4d2e5ec250bf3c6cc' as 'archived_…
…PhantRepos/phant-monitor'
- Loading branch information
Showing
9 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
tmp | ||
/node_modules/ | ||
*.swp | ||
npm-debug.log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": "func", | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
before_script: | ||
- npm install -g grunt-cli | ||
notifications: | ||
email: | ||
recipients: | ||
- [email protected] | ||
on_success: change | ||
on_failure: change |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
// Show elapsed time at the end | ||
require('time-grunt')(grunt); | ||
// Load all grunt tasks | ||
require('load-grunt-tasks')(grunt); | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
nodeunit: { | ||
files: ['test/**/*_test.js'] | ||
}, | ||
jshint: { | ||
options: { | ||
jshintrc: '.jshintrc', | ||
reporter: require('jshint-stylish') | ||
}, | ||
gruntfile: { | ||
src: 'Gruntfile.js' | ||
}, | ||
lib: { | ||
src: ['lib/**/*.js'] | ||
}, | ||
test: { | ||
src: ['test/**/*.js'] | ||
} | ||
}, | ||
watch: { | ||
gruntfile: { | ||
files: '<%= jshint.gruntfile.src %>', | ||
tasks: ['jshint:gruntfile'] | ||
}, | ||
lib: { | ||
files: '<%= jshint.lib.src %>', | ||
tasks: ['jshint:lib', 'nodeunit'] | ||
}, | ||
test: { | ||
files: '<%= jshint.test.src %>', | ||
tasks: ['jshint:test', 'nodeunit'] | ||
} | ||
} | ||
}); | ||
|
||
// Default task. | ||
grunt.registerTask('default', ['jshint', 'nodeunit']); | ||
|
||
}; |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
your stream %s is old |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* phant-monitor | ||
* https://github.com/sparkfun/phant-monitor | ||
* | ||
* Copyright (c) 2014 SparkFun Electronics | ||
* Licensed under the GPL v3 license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/**** Module dependencies ****/ | ||
var mailer = require('nodemailer'), | ||
util = require('util'), | ||
fs = require('fs'); | ||
|
||
/**** app prototype ****/ | ||
var app = Monitor.prototype; | ||
|
||
/**** Expose Monitor ****/ | ||
exports = module.exports = Monitor; | ||
|
||
function Monitor(options) { | ||
|
||
if (! (this instanceof Monitor)) { | ||
return new Monitor(options); | ||
} | ||
|
||
util._extend(this, options || {}); | ||
|
||
this.email_template = fs.readFileSync('./email_template', 'utf8'); | ||
|
||
// this sets up the smtp connection pool. | ||
// better to do it for each message? | ||
this.smtpTransport = mailer.createTransport('SMTP', { | ||
service: 'Gmail', | ||
auth: { | ||
user: '[email protected]', | ||
pass: 'userpass' | ||
} | ||
}); | ||
} | ||
|
||
app.last_mailed = {}; | ||
|
||
app.run = function () { | ||
setInterval(this.check.bind(this), this.interval); | ||
}; | ||
|
||
app.check = function () { | ||
var self = this; | ||
this.metadata.all(function (err, streams) { | ||
var now = new Date(); | ||
var then = null; | ||
var age = self.age; | ||
|
||
if(err || ! streams.length) { | ||
return; | ||
} | ||
|
||
streams.forEach(function(stream) { | ||
then = self.last_mailed[stream.id] || stream.last_push; | ||
if ((now - then) > age) { | ||
self.last_mailed[stream.id] = now; | ||
console.log(util.format(self.email_template, stream.id)); | ||
// self.smtpTransport.sendMail({ | ||
// from: '', | ||
// to: '', | ||
// subject: '', | ||
// text: util.format(self.email_template, stream.id) | ||
// }, function(error, response){ | ||
// if (error) { | ||
// console.log(error); | ||
// } else { | ||
// console.log("Message sent: " + response.message); | ||
// } | ||
// }); | ||
} | ||
}); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env node | ||
|
||
var Meta = require('phant-meta-json'), | ||
Storage = require('phant-stream-csv'), | ||
Monitor = require('./index'); | ||
|
||
var meta = Meta({ | ||
directory: process.env.PHANT_STORAGEDIR || 'tmp' | ||
}); | ||
|
||
var monitor = Monitor({ | ||
metadata: meta, | ||
interval: 2 * 1000, // 2 seconds | ||
age: 2 * 60 * 60 * 1000 // 2 hours | ||
}); | ||
|
||
monitor.run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "phant-monitor", | ||
"version": "0.0.0", | ||
"description": "watches phant streams", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "BSD-2-Clause", | ||
"dependencies": { | ||
"nodemailer": "~0.7.0" | ||
} | ||
} |