From 2956520b35bdf1de9fe2bc9af73fc3f85062ca32 Mon Sep 17 00:00:00 2001 From: uribes78 Date: Mon, 8 Jan 2018 17:58:51 -0700 Subject: [PATCH 1/2] Change frequency validation Change frequency validation to allow more than one digit, also the timer --- optionsparser.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/optionsparser.js b/optionsparser.js index b1672ae..50b9301 100644 --- a/optionsparser.js +++ b/optionsparser.js @@ -4,6 +4,8 @@ const util = require('util'); // frequency: '2s' exports.getFrequency = function(options) { let f = {}; + let g = null; + let regexp = /^(\d+)([smh])$/; if(!options || !options.frequency) { f.mode = 'once'; @@ -20,13 +22,14 @@ exports.getFrequency = function(options) { f.interval = 2000; // check for alert condition every 2 seconds return f; } - else if(options.frequency.length !== 2 || isNaN(options.frequency[0])) { + else if(regexp.test(options.frequency)) { + g = regexp.exec(options.frequency); + } else throw "Invalid frequency. Try something like 'once', 'onalert', '2m' or '1h'"; - } f.mode = 'time'; - let n = parseInt(options.frequency[0]); - let s = options.frequency[1]; + let n = parseInt(g[1]); + let s = g[2]; switch(s) { case 's': f.interval = n * 1000; break; @@ -91,4 +94,4 @@ exports.getDiskUsedAlertThreshold = function(diskoptions) { } return parseInt(u.split('>')[1].split('%')[0]); -} \ No newline at end of file +} From 981c55c1aa4e3fe143e657f708a78e7f07643dd5 Mon Sep 17 00:00:00 2001 From: uribes78 Date: Sun, 18 Mar 2018 10:37:08 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 50e4670..4879b03 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ npm install microstats const microstats = require('microstats') // Event emits -microstats.on('memory', function(value) { console.log('MEMORY:', memory } -microstats.on('cpu', function(value) { console.log('CPU:', memory } -microstats.on('disk', function(value) { console.log('DISK:', memory } +microstats.on('memory', function(value) { console.log('MEMORY:', value) }) +microstats.on('cpu', function(value) { console.log('CPU:', value) }) +microstats.on('disk', function(value) { console.log('DISK:', value) }) let options = {} microstats.start(options, function(err) {