-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration.js
60 lines (47 loc) · 1.7 KB
/
integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const { validateOptions, parseUserOptions } = require('./server/userOptions');
const { setLogger, getLogger } = require('./server/logging');
const {
buildIgnoreResults,
organizeEntities,
parseErrorToReadableJson
} = require('./server/dataTransformations');
const searchEntities = require('./server/searchEntities');
const assembleLookupResults = require('./server/assembleLookupResults');
const onMessageFunctions = require('./server/onMessage');
const doLookup = async (entities, userOptions, cb) => {
const Logger = getLogger();
try {
Logger.debug({ entities }, 'Entities');
const { searchableEntities, nonSearchableEntities } = organizeEntities(entities);
const options = parseUserOptions(userOptions);
const { alerts, incidents, devices, kustoQueryResults } = await searchEntities(
searchableEntities,
options
);
Logger.trace({ alerts, incidents, devices, kustoQueryResults });
const lookupResults = assembleLookupResults(
entities,
alerts,
incidents,
devices,
kustoQueryResults,
options
);
const ignoreResults = buildIgnoreResults(nonSearchableEntities);
Logger.trace({ lookupResults, ignoreResults }, 'Lookup Results');
cb(null, lookupResults.concat(ignoreResults));
} catch (error) {
const err = parseErrorToReadableJson(error);
Logger.error({ error, formattedError: err }, 'Get Lookup Results Failed');
cb({ detail: error.message || 'Lookup Failed', err });
}
};
const onMessage = ({ action, data: actionParams }, options, callback) =>
onMessageFunctions[action](actionParams, options, callback);
module.exports = {
startup: setLogger,
validateOptions,
doLookup,
onMessage
};