Skip to content

Commit b4891ac

Browse files
committed
Initial checkin
0 parents  commit b4891ac

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SumoLogic AWS Lambda Functions
2+
==============================
3+
4+
This repository contains various Lambda functions to send data from AWS services to SumoLogic
5+
6+
Usage
7+
-----
8+
9+
Please look at the specific folder for details.

cloudwatchlogs/cloudwatchlogs.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
var https = require('https');
3+
var zlib = require('zlib');
4+
5+
exports.handler = function(event, context) {
6+
///////////////////////////////////////////////////////////////////////////////////////////////////////////
7+
// Remember to change the hostname and path to match your collection API and specific HTTP-source endpoint
8+
// See more at: https://service.sumologic.com/help/Default.htm#Collector_Management_API.htm
9+
///////////////////////////////////////////////////////////////////////////////////////////////////////////
10+
var options = { 'hostname': 'collectors.sumologic.com',
11+
'path': 'https://collectors.sumologic.com/receiver/v1/http/<XXX>',
12+
'method': 'POST'
13+
};
14+
var zippedInput = new Buffer(event.awslogs.data, 'base64');
15+
16+
zlib.gunzip(zippedInput, function(e, buffer) {
17+
if (e) { context.fail(e); }
18+
19+
awslogsData = JSON.parse(buffer.toString('ascii'));
20+
21+
console.log(awslogsData);
22+
23+
if (awslogsData.messageType === "CONTROL_MESSAGE") {
24+
console.log("Control message");
25+
context.succeed("Success");
26+
}
27+
28+
var req = https.request(options, function(res) {
29+
var body = '';
30+
console.log('Status:', res.statusCode);
31+
res.setEncoding('utf8');
32+
res.on('data', function(chunk) { body += chunk; });
33+
res.on('end', function() {
34+
console.log('Successfully processed HTTPS response');
35+
context.succeed(); });
36+
});
37+
38+
req.on('error', context.fail);
39+
40+
stream=awslogsData.logStream;
41+
group=awslogsData.logGroup;
42+
awslogsData.logEvents.forEach(function(val, idx, arr) {
43+
val.logStream = stream;
44+
val.logGroup = group;
45+
req.write(JSON.stringify(val) + '\n');
46+
});
47+
req.end();
48+
});
49+
};
50+

0 commit comments

Comments
 (0)