From e3d767ec552591aa79cc1e72bc4b0f8a0fbf9b83 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Fri, 2 Aug 2019 11:38:07 -0400 Subject: [PATCH 1/2] Added support for S3 access logs --- handlers/formatS3access.js | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 handlers/formatS3access.js diff --git a/handlers/formatS3access.js b/handlers/formatS3access.js new file mode 100644 index 0000000..b784139 --- /dev/null +++ b/handlers/formatS3access.js @@ -0,0 +1,64 @@ +exports.process = function(config) { + console.log('formatS3access for S3 hosted application logs'); + if (!config.data || + (!config.data.length && config.data.length !== 0)) { + return Promise.reject('Received unexpected S3 log format:' + + JSON.stringify(config.data)); + } + + var output = []; + var fields = [ + 'bucket_owner', + 'bucket', + 'time', + 'zone', + 'remote_ip', + 'requester', + 'request_id', + 'operation', + 'key', + 'request_uri', + 'http_status', + 'error_code', + 'bytes_sent', + 'object_size', + 'total_time', + 'turn_around_time', + 'referrer', + 'user_agent', + 'version_id', + 'host_id', + 'signature_version', + 'cipher_suite', + 'authentication_type', + 'host_header', + 'tls_version' + ]; + var numRows = config.data.length; + var numCols; + var i; + var j; + var row; + var item; + + for (i = 0; i < numRows; i++) { + row = config.data[i]; + if (row.length !== 25) { + console.log('Expected 25 columns in row. Found ' + row.length + ': ' + + config.data[i]); + } + + item = {}; + numCols = Math.min(row.length, fields.length); + for (j = 0; j < numCols; j++) { + item[fields[j]] = row[j]; + } + item.time = item.time.replace(/\:/,' ').replace(/\[/,''); + item.zone = item.zone.replace(/\]/,''); + item[config.dateField] = new Date(item.time + item.zone); + + output.push(item); + } + config.data = output; + return Promise.resolve(config); +}; \ No newline at end of file From 85f09a2e69eee6f7975fe6e689203a00e74d01ab Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Fri, 2 Aug 2019 13:42:46 -0400 Subject: [PATCH 2/2] Fixed ESLint errors --- handlers/formatS3access.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/handlers/formatS3access.js b/handlers/formatS3access.js index b784139..a02f646 100644 --- a/handlers/formatS3access.js +++ b/handlers/formatS3access.js @@ -53,12 +53,11 @@ exports.process = function(config) { for (j = 0; j < numCols; j++) { item[fields[j]] = row[j]; } - item.time = item.time.replace(/\:/,' ').replace(/\[/,''); - item.zone = item.zone.replace(/\]/,''); + item.time = item.time.replace(/:/, ' ').replace(/\[/, ''); + item.zone = item.zone.replace(/\]/, ''); item[config.dateField] = new Date(item.time + item.zone); - output.push(item); } config.data = output; return Promise.resolve(config); -}; \ No newline at end of file +};