diff --git a/lib/utils.js b/lib/utils.js index bc7f800..fab3eb8 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -4,51 +4,59 @@ const moment = require('moment'); class Client extends CloudGenix { - getAllEvents(options = { - 'timeDelta': 10, - 'type': 'alarm' + getAllEvents (options = { + 'type': 'alarm', + 'timeDelta': null, + 'exclude': [] }) { - // eslint-disable-next-line no-ternary, no-prototype-builtins - options.timeDelta = options.hasOwnProperty('timeDelta') ? options.timeDelta : 10; + if (!Object.prototype.hasOwnProperty.call(options, 'type')) { + options.type = 'alarm'; + } - // eslint-disable-next-line no-ternary, no-prototype-builtins - options.type = options.hasOwnProperty('type') ? options.type : 'alarm'; + if (!Object.prototype.hasOwnProperty.call(options, 'exclude')) { + options.exclude = []; + } - const startTime = moment().subtract(options.timeDelta, 'm').toISOString(); - const endTime = moment().toISOString(); + if (options.timeDelta) { + options.startTime = moment().subtract(options.timeDelta, 'm') + .toISOString(); + options.endTime = moment().toISOString(); + } else { + options.startTime = null; + options.endTime = null; + } let offset = null; let items = []; const events = () => this.queryEvents({ '_offset': offset, - 'start_time': startTime, - 'end_time': endTime, + 'start_time': options.startTime, + 'end_time': options.endTime, 'limit': {}, - 'query': { 'type': options.type }, - // 'query': {}, + 'query': {'type': options.type}, 'severity': [], 'summary': false - }).then(value => { + }).then((value) => { debug('Query Events: %o', value); - // eslint-disable-next-line no-underscore-dangle - if (value._offset) { - - // eslint-disable-next-line no-underscore-dangle - offset = value._offset; + if (value._offset) { // eslint-disable-line no-underscore-dangle + offset = value._offset; // eslint-disable-line no-underscore-dangle items = items.concat(value.items); return events(); } return items.concat(value.items); - }); // eslint: events function - return events(); + }); // eslint: events + + return events().then((value) => value.filter((item) => options.exclude + .includes(item.code) === false)); // eslint: return events + } // eslint: getAllEvents } // eslint: Class Client -module.exports = Client; \ No newline at end of file +module.exports = Client;