Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

Commit

Permalink
ability to exclude events
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit Goel committed Sep 8, 2017
1 parent aca3c2b commit 773d46b
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
module.exports = Client;

0 comments on commit 773d46b

Please sign in to comment.