Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Merge commit '325bb1915dc9f606eff5d3a4d2e5ec250bf3c6cc' as 'archived_…
Browse files Browse the repository at this point in the history
…PhantRepos/phant-monitor'
  • Loading branch information
bboyho committed Nov 15, 2017
2 parents 4d505b1 + 325bb19 commit 1d183bd
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 0 deletions.
4 changes: 4 additions & 0 deletions archived_PhantRepos/phant-monitor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tmp
/node_modules/
*.swp
npm-debug.log
14 changes: 14 additions & 0 deletions archived_PhantRepos/phant-monitor/.jshintrc
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
}
11 changes: 11 additions & 0 deletions archived_PhantRepos/phant-monitor/.travis.yml
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
48 changes: 48 additions & 0 deletions archived_PhantRepos/phant-monitor/Gruntfile.js
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.
1 change: 1 addition & 0 deletions archived_PhantRepos/phant-monitor/email_template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
your stream %s is old
80 changes: 80 additions & 0 deletions archived_PhantRepos/phant-monitor/index.js
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);
// }
// });
}
});
});
};
17 changes: 17 additions & 0 deletions archived_PhantRepos/phant-monitor/monitor
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();
14 changes: 14 additions & 0 deletions archived_PhantRepos/phant-monitor/package.json
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"
}
}

0 comments on commit 1d183bd

Please sign in to comment.