Skip to content

Commit

Permalink
Added some debug logs in mimecast collector (#280)
Browse files Browse the repository at this point in the history
* Added some debug logs in mimecast collector

* Changes as per suggestion

* Upgraded package version
  • Loading branch information
sameerbag committed May 25, 2022
1 parent 0ee9c73 commit b5bedec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
9 changes: 2 additions & 7 deletions collectors/mimecast/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ class MimecastCollector extends PawsCollector {

if (state.stream === Siem_Logs || state.stream === Malware_Feed) {
AlLogger.info(`MIME000001 Collecting data for ${state.stream}`);
}
else{
} else {
AlLogger.info(`MIME000002 Collecting data for ${state.stream} from ${state.since} till ${state.until}`);
}

utils.getAPILogs(authDetails, state, [], process.env.paws_max_pages_per_invocation)
.then(({ accumulator, nextPage }) => {
let newState;
Expand All @@ -138,7 +137,6 @@ class MimecastCollector extends PawsCollector {
else{
return callback(error);
}

});
}

Expand All @@ -152,11 +150,8 @@ class MimecastCollector extends PawsCollector {
}
}
else {

const untilMoment = moment(curState.until);

const { nextUntilMoment, nextSinceMoment, nextPollInterval } = calcNextCollectionInterval('hour-day-progression', untilMoment, this.pollInterval);

return {
stream: curState.stream,
since: nextSinceMoment.utc().format(),
Expand Down
2 changes: 1 addition & 1 deletion collectors/mimecast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mimecast-collector",
"version": "1.0.17",
"version": "1.0.18",
"description": "Alert Logic AWS based Mimecast Log Collector",
"repository": {},
"private": true,
Expand Down
18 changes: 14 additions & 4 deletions collectors/mimecast/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ function getAPILogs(authDetails, state, accumulator, maxPagesPerInvocation) {
}

let requestHeaders = generateHeaders(authDetails, applicationDetails.uri);
let url = `https://${authDetails.baseUrl}${applicationDetails.uri}`;

AlLogger.debug('MIME00009 calling url: ', url);

request.post({
url: `https://${authDetails.baseUrl}${applicationDetails.uri}`,
url: url,
headers: requestHeaders,
body: JSON.stringify(applicationDetails.payload)
}, function (error, response, body) {
Expand Down Expand Up @@ -59,6 +62,7 @@ function getAPILogs(authDetails, state, accumulator, maxPagesPerInvocation) {
if(applicationDetails.payload.data[0].token){
nextPage = applicationDetails.payload.data[0].token;
}
AlLogger.debug('MIME000011 accumulated first element: ', accumulator[1]);
return resolve({ accumulator, nextPage });
}
if (response.headers && response.headers['mc-siem-token']) {
Expand All @@ -70,10 +74,10 @@ function getAPILogs(authDetails, state, accumulator, maxPagesPerInvocation) {
accumulator.push(...body.objects);
nextPage = response.headers['x-mc-threat-feed-next-token'];
}
else{
else {
nextPage = undefined;
//if next token is not present in responce then it will set last request token value to nextPage
if(applicationDetails.payload.data[0].token){
if (applicationDetails.payload.data[0].token) {
nextPage = applicationDetails.payload.data[0].token;
}
return resolve({ accumulator, nextPage });
Expand Down Expand Up @@ -222,13 +226,19 @@ function generateHeaders(authDetails, uri) {
hmac.end(); // can't read from the stream until you call end()
signature = hmac.read().toString('base64');

return {
let returnObj = {
"Authorization": `MC ${authDetails.accessKey}:${signature}`,
"x-mc-app-id": authDetails.appId,
"x-mc-date": hdrDate,
"x-mc-req-id": requestId,
"Content-Type": 'application/json'
};

AlLogger.debug('MIME000012 url App Id: ', returnObj['x-mc-app-id']);
AlLogger.debug('MIME000012 url Date: ', returnObj['x-mc-date']);
AlLogger.debug('MIME000012 url Request ID: ', returnObj['x-mc-req-id']);

return returnObj;
}

function getTypeIdAndTsPaths(stream) {
Expand Down

0 comments on commit b5bedec

Please sign in to comment.