Skip to content

Commit 7b166f8

Browse files
authored
Merge pull request #100 from njparisi/support-for-metadata-fields
added meta data field support
2 parents 253ccc6 + 208510d commit 7b166f8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

cloudwatchlogs-with-dlq/cloudwatchlogs_lambda.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ function getConfig(env) {
7070
// SumoLogic Endpoint to post logs
7171
"SumoURL": env.SUMO_ENDPOINT,
7272

73-
// The following parameters override the sourceCategory, sourceHost and sourceName metadata fields within SumoLogic.
73+
// The following parameters override the sourceCategory, sourceHost, sourceName and sourceFields metadata fields within SumoLogic.
7474
// Not these can also be overridden via json within the message payload. See the README for more information.
7575
"sourceCategoryOverride": ("SOURCE_CATEGORY_OVERRIDE" in env) ? env.SOURCE_CATEGORY_OVERRIDE: '', // If none sourceCategoryOverride will not be overridden
76-
"sourceHostOverride": ("SOURCE_HOST_OVERRIDE" in env) ? env.SOURCE_HOST_OVERRIDE : '', // If none sourceHostOverride will not be set to the name of the logGroup
77-
"sourceNameOverride": ("SOURCE_NAME_OVERRIDE" in env) ? env.SOURCE_NAME_OVERRIDE : '', // If none sourceNameOverride will not be set to the name of the logStream
76+
"sourceFieldsOverride": ("SOURCE_FIELDS_OVERRIDE" in env) ? env.SOURCE_FIELDS_OVERRIDE: '', // If none sourceFieldsOverride will not be overridden
77+
"sourceHostOverride": ("SOURCE_HOST_OVERRIDE" in env) ? env.SOURCE_HOST_OVERRIDE : '', // If none sourceHostOverride will not be set to the name of the logGroup
78+
"sourceNameOverride": ("SOURCE_NAME_OVERRIDE" in env) ? env.SOURCE_NAME_OVERRIDE : '', // If none sourceNameOverride will not be set to the name of the logStream
7879
"SUMO_CLIENT_HEADER": env.SUMO_CLIENT_HEADER || 'cwl-aws-lambda',
7980
// CloudWatch logs encoding
8081
"encoding": env.ENCODING || 'utf-8', // default is utf-8

cloudwatchlogs-with-dlq/sumo-dlq-function-utils/lib/sumologsclient.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ function SumoLogsClient(config) {
1515

1616
SumoLogsClient.prototype.generateHeaders = function(config, message, awslogsData) {
1717
var sourceCategory = config.sourceCategoryOverride || '';
18+
var sourceFields = config.sourceFieldsOverride || '';
1819
var sourceName = config.sourceNameOverride || ((awslogsData) ? awslogsData.logStream : '');
1920
var sourceHost = config.sourceHostOverride || ((awslogsData) ? awslogsData.logGroup : '');
2021

2122
var headerObj = {
2223
'X-Sumo-Name':sourceName, 'X-Sumo-Category':sourceCategory,
23-
'X-Sumo-Host':sourceHost, 'X-Sumo-Client': config.SUMO_CLIENT_HEADER
24+
'X-Sumo-Host':sourceHost, 'X-Sumo-Fields':sourceFields,
25+
'X-Sumo-Client': config.SUMO_CLIENT_HEADER
2426
};
2527

26-
var metadataMap = {category: "X-Sumo-Category", sourceName: "X-Sumo-Name", sourceHost: "X-Sumo-Host"};
28+
var metadataMap = {category: "X-Sumo-Category", sourceName: "X-Sumo-Name", sourceHost: "X-Sumo-Host", sourceFieldsOverride: "X-Sumo-Fields"};
2729
if (message.hasOwnProperty('_sumo_metadata')) {
2830
var metadataOverride = message._sumo_metadata;
2931
Object.getOwnPropertyNames(metadataOverride).forEach( function(property) {
@@ -47,6 +49,7 @@ SumoLogsClient.prototype.createPromises = function(messages, is_compressed) {
4749
'X-Sumo-Name': headerArray[0],
4850
'X-Sumo-Category': headerArray[1],
4951
'X-Sumo-Host': headerArray[2],
52+
'X-Sumo-Fields': headerArray[3],
5053
'X-Sumo-Client': self.SUMO_CLIENT_HEADER
5154
};
5255
var options = Object.assign({}, self.options);
@@ -100,7 +103,7 @@ SumoLogsClient.prototype.postToSumo = function(messages, is_compressed) {
100103
};
101104

102105
SumoLogsClient.prototype.getMetaDataKey = function(headerObj) {
103-
return headerObj['X-Sumo-Name'] + ':' + headerObj['X-Sumo-Category'] + ':' + headerObj['X-Sumo-Host'];
106+
return headerObj['X-Sumo-Name'] + ':' + headerObj['X-Sumo-Category'] + ':' + headerObj['X-Sumo-Host'] + ':' + headerObj['X-Sumo-Fields'];
104107
};
105108

106109

0 commit comments

Comments
 (0)