Comparing version 0.0.8 to 0.1.0
@@ -1,20 +0,40 @@ | ||
{ | ||
targets: [ | ||
{ | ||
name: 'my_service', | ||
path: '/path/to/error.log', | ||
interval: 60, | ||
levels: [1, 30, 60], | ||
extractor: function(line) { | ||
return line.replace(/#012/g, '\n'); | ||
}, | ||
atwho: ['@hit9'], | ||
room: 12345 | ||
} | ||
/** | ||
* Example configuration for errdog | ||
*/ | ||
/** | ||
* conditions | ||
*/ | ||
var intensity = require('./conditions/intensity'); | ||
/** | ||
* alerters | ||
*/ | ||
var console_ = require('./alerters/console'); | ||
var hipchat = require('./alerters/hipchat'); | ||
/** | ||
* target `foo` | ||
*/ | ||
var foo = { | ||
name: 'foo', | ||
path: '/path/to/foo.error.log', | ||
extract: function(line) {return line;}, | ||
alerters: [ | ||
[console_], | ||
[hipchat, {token: 'xxx', room: 123, atwho: ['@here']}] | ||
], | ||
hipchat: { | ||
room: 123456, // default room | ||
token: 'xxxyyyzzz', | ||
notify: 1 | ||
} | ||
} | ||
conditions: [ | ||
[intensity] | ||
] | ||
}; | ||
/** | ||
* Exports targets | ||
*/ | ||
exports = module.exports = [ | ||
foo | ||
]; |
129
index.js
/** | ||
* Watch error log files and send notification to hipchat on errors. | ||
* Node Error Dog, Notify you on error logs! | ||
* https://github.com/eleme/node-error-dog.git | ||
* | ||
* The MIT License (MIT) | ||
* Copyright (c) 2014 hit9 | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
* OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
var fs = require('fs'); | ||
var events = require('events'); | ||
var util = require('util'); | ||
var request = require('request'); | ||
var Tail = require('tail').Tail; | ||
@@ -12,9 +33,3 @@ | ||
/** | ||
* Global config (to be updated) | ||
*/ | ||
var config; | ||
/** | ||
* Log one message to process stdout | ||
* Log one message to process stdout. | ||
* | ||
@@ -33,90 +48,40 @@ * @param {String} format | ||
/** | ||
* Alert hipchat | ||
* Watch a target | ||
* | ||
* @param {Number} room | ||
* @param {String} from | ||
* @param {String} message | ||
* @param {String} color | ||
*/ | ||
function alert(room, from, message, color, notify) { | ||
var url = util.format( | ||
'http://api.hipchat.com/v1/rooms/message' + | ||
'?format=json&auth_token=%s', config.hipchat.token); | ||
var form = { | ||
'room_id': room, | ||
from: from, | ||
message: message, | ||
notify: notify || 1, | ||
color: color || 'gray', | ||
'message_format': 'text' | ||
}; | ||
return request.post({url: url, form: form}, function(err, resp, body) { | ||
if (err) { | ||
log('Error alert:', err); | ||
} | ||
else { | ||
log('Alert: %s %s', from, message); | ||
} | ||
}); | ||
} | ||
/** | ||
* Watch target error log file | ||
* | ||
* @param {Object} target | ||
* | ||
* target: | ||
* | ||
* name string, required | ||
* path string, required | ||
* interval number, optional (default: 30) | ||
* levels array, optional (default: [1, 15, 30]) | ||
* extractor function, optional (default: function(line){return line;}) | ||
*/ | ||
function watch(target) { | ||
var path = target.path; | ||
var name = target.name; | ||
var interval = target.interval || 30; | ||
var levels = target.levels || [1, 15, 30]; | ||
var extractor = target.extractor || function(line) {return line;}; | ||
var atwho = target.atwho || []; | ||
var colors = ['gray', 'yellow', 'red']; | ||
var room = target.room || config.hipchat.room; | ||
target.extract = target.extract || function(line) { | ||
return line; | ||
}; | ||
var lines = []; | ||
var emitter = new events.EventEmitter(); | ||
var tail = new Tail(path); | ||
tail = new Tail(target.path); | ||
tail.on('line', function(line) { | ||
return lines.push(extractor(line)); | ||
emitter.emit('line', target.extract(line)); | ||
}); | ||
setInterval(function() { | ||
for (var i = levels.length - 1; i >= 0; i--) { | ||
if (levels[i] <= lines.length && lines.length > 0) { | ||
var from = name; | ||
var message = util.format('/code %s', lines.slice(0, 15).join('\n')); | ||
var color = colors[i]; | ||
alert(room, name, message, color, config.hipchat.notify); | ||
target.alerters.forEach(function(list){ | ||
var alerter = list[0]; | ||
var settings = list[1] || {}; | ||
alerter.init(emitter, target, log, settings); | ||
}); | ||
if (i === levels.length - 1 && atwho.length > 0) { | ||
var message_ = atwho.join(' ') + util. | ||
format(' %d error messages in %d seconds', lines.length, interval); | ||
alert(room, name, message_, color, | ||
config.hipchat.notify); | ||
} | ||
} | ||
} | ||
lines = []; | ||
}, interval * 1000); | ||
target.conditions.forEach(function(list){ | ||
var condition = list[0]; | ||
var settings = list[1] || {}; | ||
condition.init(emitter, target, log, settings); | ||
}); | ||
} | ||
/** | ||
* Watch all targets. | ||
*/ | ||
(function() { | ||
config = eval('_ = ' + fs.readFileSync(process.argv[2])); | ||
config.targets.forEach(function(target) { | ||
var targets = require(process.argv[2]); | ||
targets.forEach(function(target) { | ||
watch(target); | ||
}); | ||
})(); |
{ | ||
"name": "errdog", | ||
"version": "0.0.8", | ||
"version": "0.1.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/hit9/errdog.git" | ||
"url": "git://github.com/eleme/node-error-dog.git" | ||
}, | ||
"author": "hit9 <nz2324@126.com>", | ||
"author": "hit9 <wangchao@ele.me>", | ||
"description": "Notify you on error logs!", | ||
"dependencies": { | ||
@@ -14,5 +15,5 @@ "request": "^2.48.0", | ||
"bin": { | ||
"errdog": "./errdog.js" | ||
"errdog": "./bin/errdog.js" | ||
}, | ||
"license": "MIT" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
7655
9
255
1
24