Skip to content

Commit

Permalink
Merge README changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ikemsley committed Oct 2, 2017
2 parents 2ac34a1 + 0ef446c commit d72c82c
Show file tree
Hide file tree
Showing 22 changed files with 778 additions and 176 deletions.
15 changes: 8 additions & 7 deletions Master/azcollect.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* -----------------------------------------------------------------------------
* @copyright (C) 2017, Alert Logic, Inc
* @doc
*
*
* The module for communicating with Alertlogic Azcollect service.
*
*
* @end
* -----------------------------------------------------------------------------
*/

const m_alServiceC = require('../lib/al_servicec');
const m_version = require('./version');

Expand All @@ -27,7 +27,7 @@ class Azcollect extends m_alServiceC.AlServiceC {
super(apiEndpoint, 'azcollect', 'v1',
aimsCreds, process.env.TMP);
}

_o365RegisterBody() {
let o365AuditStreams = JSON.parse(process.env.O365_CONTENT_STREAMS);
let registerParams = {};
Expand All @@ -47,15 +47,16 @@ class Azcollect extends m_alServiceC.AlServiceC {
}};
return Object.assign({}, commonParams , configParams);
}

register_o365() {
let regBody = this._o365RegisterBody();
return this.post(`/register/o365`, {body: regBody});
}

checkin(collectorType, collectorId, statusVal, descriptionVal) {
let statusBody = {
collector_version : m_version.getVersion(),
type : collectorType,
version : m_version.getVersion(),
status : statusVal,
description : descriptionVal
};
Expand Down
6 changes: 3 additions & 3 deletions Master/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const m_appSettings = require('./appsettings');

exports.checkUpdate = function (context, AlertlogicMasterTimer, callback) {
if (process.env.APP_INGEST_ENDPOINT && process.env.APP_AZCOLLECT_ENDPOINT) {
context.log('DEBUG: Reuse Ingest endpoint', process.env.APP_INGEST_ENDPOINT);
context.log('DEBUG: Reuse Azcollect endpoint', process.env.APP_AZCOLLECT_ENDPOINT);
context.log.verbose('Reuse Ingest endpoint', process.env.APP_INGEST_ENDPOINT);
context.log.verbose('Reuse Azcollect endpoint', process.env.APP_AZCOLLECT_ENDPOINT);
return callback(null);
} else {
// Endpoint settings do not exist. Update them.
let alApiEndpoint = process.env.CUSTOMCONNSTR_APP_AL_API_ENDPOINT;
let alApiEndpoint = process.env.CUSTOMCONNSTR_APP_AL_API_ENDPOINT;
let alResidency = process.env.CUSTOMCONNSTR_APP_AL_RESIDENCY;
let aimsCreds = {
access_key_id : process.env.CUSTOMCONNSTR_APP_CI_ACCESS_KEY_ID,
Expand Down
10 changes: 5 additions & 5 deletions Master/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function (context, AlertlogicMasterTimer) {
if (endpointsError) {
return asyncCallback(endpointsError);
}
context.log('INFO: Alertlogic endpoints updated.');
context.log.info('Alertlogic endpoints updated.');
return asyncCallback(null);
});
},
Expand All @@ -41,7 +41,7 @@ module.exports = function (context, AlertlogicMasterTimer) {
if (azcollectError) {
return asyncCallback(azcollectError);
}
context.log('INFO: O365 source registered', collectorId);
context.log.info('O365 source registered', collectorId);
return asyncCallback(null, azcollectSvc);
});
},
Expand All @@ -52,15 +52,15 @@ module.exports = function (context, AlertlogicMasterTimer) {
if (azcollectError) {
return asyncCallback(`Checkin failed ${azcollectError}`);
}
context.log('INFO: O365 source checkin OK', checkinResp);
context.log.info('O365 source checkin OK', checkinResp);
return asyncCallback(null);
});
}
],
function(error, results) {
if (error) {
context.log('ERROR: Master error ', error);
context.log.error('Master error ', error);
}
context.done();
context.done(error);
});
};
14 changes: 6 additions & 8 deletions Master/o365collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const m_o365mgmnt = require('../lib/o365_mgmnt');

exports.checkRegister = function (context, AlertlogicMasterTimer, azcollectSvc, callback) {
if (process.env.O365_COLLECTOR_ID && process.env.O365_HOST_ID) {
context.log('DEBUG: Reuse collector id', process.env.O365_COLLECTOR_ID);
context.log.verbose('Reuse collector id', process.env.O365_COLLECTOR_ID);
return callback(null, process.env.O365_COLLECTOR_ID);
} else {
// Collector is not registered.
Expand All @@ -27,7 +27,6 @@ exports.checkRegister = function (context, AlertlogicMasterTimer, azcollectSvc,
O365_COLLECTOR_ID: resp.source.id,
O365_HOST_ID: resp.source.host.id
};
context.log(newSettings);
m_appSettings.updateAppsettings(newSettings,
function(settingsError) {
if (settingsError) {
Expand All @@ -44,7 +43,7 @@ exports.checkRegister = function (context, AlertlogicMasterTimer, azcollectSvc,

exports.checkin = function (context, AlertlogicMasterTimer, azcollectSvc, callback) {
return m_o365mgmnt.subscriptionsList(
function(listErr, subscrptions, httpRequest, response) {
function(listErr, subscriptions, httpRequest, response) {
if (listErr) {
azcollectSvc.checkin('o365',
process.env.O365_COLLECTOR_ID, 'error', `${listErr}`)
Expand All @@ -54,15 +53,14 @@ exports.checkin = function (context, AlertlogicMasterTimer, azcollectSvc, callba
.catch(function(exception) {
return callback(`Unable to checkin ${exception}`);
});
return callback(listErr);
} else {
return _checkEnableAuditStreams(context, subscrptions,
return _checkEnableAuditStreams(context, subscriptions,
function(enableErr, checkResults) {
if (enableErr) {
azcollectSvc.checkin('o365',
process.env.O365_COLLECTOR_ID, 'error', `${enableErr}`)
.then(resp => {
callback(null, resp);
return callback(null, resp);
})
.catch(function(exception) {
return callback(`Unable to checkin ${exception}`);
Expand All @@ -71,7 +69,7 @@ exports.checkin = function (context, AlertlogicMasterTimer, azcollectSvc, callba
azcollectSvc.checkin('o365',
process.env.O365_COLLECTOR_ID, 'ok', `${checkResults}`)
.then(resp => {
callback(null, resp);
return callback(null, resp);
})
.catch(function(exception) {
return callback(`Unable to checkin ${exception}`);
Expand All @@ -96,7 +94,7 @@ var _checkEnableAuditStreams = function(context, listedStreams, callback) {
currentStream.webhook &&
currentStream.webhook.status === 'enabled' &&
currentStream.webhook.address === webhookURL) {
context.log('DEBUG: Stream already enabled', stream);
context.log.verbose('Stream already enabled', stream);
return asyncCallback(null, stream);
} else {
let webhook = { webhook : {
Expand Down
6 changes: 3 additions & 3 deletions O365WebHook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ module.exports = function (context, event) {
return m_o365content.processNotifications(context, eventBody,
function(err) {
if (err) {
context.log(`ERROR: ${err}`);
context.log.error(`${err}`);
context.res.headers = {};
context.res.status = 500;
context.done();
context.done(err);
} else {
context.log('Debug: Success!');
context.log.info('OK!');
context.done();
}
});
Expand Down
12 changes: 6 additions & 6 deletions O365WebHook/ingest_proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const crypto = require('crypto');
module.exports.load = function(context, callback) {
protobuf.load(getCommonProtoPath(), function(err, root) {
if (err)
context.log('Error: Unable to load proto files.', err);
context.log.error('Unable to load proto files.', err);

callback(err, root);
});
Expand All @@ -34,7 +34,7 @@ module.exports.setMessage = function(context, root, content, callback) {
},
function(err, result) {
if (err)
context.log('Error: Unable to build messages.');
context.log.error('Unable to build messages.');

callback(err, result);
}
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports.setHostMetadata = function(context, root, content, callback) {

build(hostmetaType, metadataPayload, function(err, buf) {
if (err)
context.log('Error: Unable to build host_metadata.');
context.log.error('Unable to build host_metadata.');

return callback(err, buf);
});
Expand All @@ -81,7 +81,7 @@ module.exports.setBatch = function(context, root, metadata, messages, callback)

build(batchType, batchPayload, function(err, buf) {
if (err)
context.log('Error: Unable to build collected_batch.');
context.log.error('Unable to build collected_batch.');

return callback(err, buf);
});
Expand All @@ -97,7 +97,7 @@ module.exports.setBatchList = function(context, root, batches, callback) {

build(batchListType, batchListPayload, function(err, buf) {
if (err)
context.log('Error: Unable to build collected_batch_list.');
context.log.error('Unable to build collected_batch_list.');

return callback(err, buf);
});
Expand Down Expand Up @@ -148,7 +148,7 @@ function parseMessage(context, root, memo, content, callback) {

build(messageType, messagePayload, function(err, buf) {
if (err)
context.log('Error: Unable to build collected_message.');
context.log.error('Unable to build collected_message.');

memo.push(buf);
return callback(err, memo);
Expand Down
7 changes: 5 additions & 2 deletions O365WebHook/o365content.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function parseContent(context, parsedContent, callback) {

var creationTime;
if (item.CreationTime == undefined) {
context.log('WARNING: Unable to parse CreationTime from content.');
context.log.warn('Unable to parse CreationTime from content.');
creationTime = Math.floor(Date.now() / 1000);
}
else {
Expand All @@ -105,7 +105,7 @@ function parseContent(context, parsedContent, callback) {
if (err) {
return callback(`Content parsing failure. ${err}`);
} else {
context.log('DEBUG: parsedData: ', result);
context.log.verbose('parsedData: ', result);
return callback(null, result);
}
}
Expand Down Expand Up @@ -152,6 +152,9 @@ function sendToIngest(context, content, callback) {
if (err) {
return callback(`Unable to compress. ${err}`);
} else {
if (compressed.byteLength > 700000)
context.log.warn(`Compressed log batch length`,
`(${compressed.byteLength}) exceeds maximum allowed value.`);
return g_ingestc.sendO365Data(compressed)
.then(resp => {
return callback(null, resp);
Expand Down
8 changes: 8 additions & 0 deletions PostDeploymentActions/updateMasterTimer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$date = Get-Date
$min = ($date.Minute + 1) % 15
$sec = $date.Second
$new_schedule = "$sec $min-59/15 * * * *"
Write-Output "Updating Master timer trigger with ($new_schedule)."
$master_function = Get-Content '..\\wwwroot\\Master\\function.json' -raw | ConvertFrom-Json
$master_function.bindings | % {if($_.name -eq 'AlertlogicMasterTimer'){$_.schedule=$new_schedule}}
$master_function | ConvertTo-Json | set-content '..\\wwwroot\\Master\\function.json'
9 changes: 9 additions & 0 deletions PostDeploymentActions/updateUpdaterTimer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$randH = Get-Random -minimum 0 -maximum 11
$randM = Get-Random -minimum 0 -maximum 59
$randS = Get-Random -minimum 0 -maximum 59
$randH12 = $randH + 12
$new_schedule = "$randS $randM $randH,$randH12 * * *"
Write-Output "Updating Updater timer trigger with ($new_schedule)".
$master_function = Get-Content '..\\wwwroot\\Updater\\function.json' -raw | ConvertFrom-Json
$master_function.bindings | % {if($_.name -eq 'AlertlogicUpdaterTimer'){$_.schedule=$new_schedule}}
$master_function | ConvertTo-Json | set-content '..\\wwwroot\\Updater\\function.json'
Loading

0 comments on commit d72c82c

Please sign in to comment.