Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serverless-es-proxy-logs

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-es-proxy-logs - npm Package Compare versions

Comparing version 3.0.7-rc2 to 3.0.7-rc3

5

package.json
{
"name": "serverless-es-proxy-logs",
"version": "3.0.7-rc2",
"version": "3.0.7-rc3",
"license": "MIT",

@@ -71,4 +71,3 @@ "description": "A Serverless plugin to transport logs to ElasticSearch",

"fs-extra": "8.1.0",
"lodash": "4.17.15",
"socket.io-client": "^2.2.0"
"lodash": "4.17.15"
},

@@ -75,0 +74,0 @@ "devDependencies": {

119

templates/code/logsToEs.js
// v1.1.2
var https = require('https');
var zlib = require('zlib');
import io from 'socket.io-client';
import * as net from 'net';

@@ -9,6 +9,2 @@

var indexPrefix = process.env.ES_INDEX_PREFIX;
// TODO: Verify DLQ is empty
// Disable TLS validation (want to remove this for production)
// TODO: Pin proper CA.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var tags = undefined;

@@ -44,62 +40,23 @@ try {

console.log('connecting to socket ...');
const socket = io(endpoint);
socket.on('connect', () => {
const url = new URL(endpoint);
var client = new net.Socket();
client.connect(parseInt(url.port), url.host, function() {
console.log('Successfully connected to es endpoint');
console.log('Emitting data');
socket.emit(elasticsearchBulkPayload);
client.write(elasticsearchBulkPayload);
console.log('sent data');
});
socket.on('connect_failed', function() {
console.log("Sorry, there seems to be an issue with the connection!");
client.on('error', err => {
console.error(err);
process.exit(1);
});
socket.on('error', function() {
console.log('Connection failed');
client.on('close', function() {
console.log('Connection closed');
});
socket.on('connect_error', () => {
console.log('Error while connecting');
});
// post documents to the Amazon Elasticsearch Service
// put(elasticsearchBulkPayload, function(error, success, statusCode, failedItems) {
// console.log('Response: ' + JSON.stringify({
// "statusCode": statusCode
// }));
//
// if (error) {
// console.log('Error: ' + JSON.stringify(error, null, 2));
//
// if (failedItems && failedItems.length > 0) {
// console.log("Failed Items: " +
// JSON.stringify(failedItems, null, 2));
//
// var failedLogs = findFailedLogs(failedItems, elasticsearchBulkArray);
// failedLogs.forEach( failedLog => {
// console.log("Failed log content: " + JSON.stringify(failedLog, null, 2));
// });
// }
//
// context.fail(JSON.stringify(error));
// } else {
// console.log('Success: ' + JSON.stringify(success));
// context.succeed('Success');
// }
// });
});
};
function findFailedLogs(failedItems, esBulkArray) {
var failedLogs = [];
failedItems.forEach(item => {
var _id = item && item.index && item.index._id;
if (_id) {
var failedLog = esBulkArray.find(esLog => esLog && esLog.id === _id);
if (failedLog) {
failedLogs.push(failedLog);
}
}
});
return failedLogs;
}
function esDocumentArrayToPayload(esDocumentArray) {

@@ -206,53 +163,1 @@ return esDocumentArray.map(

}
function put(body, callback) {
var requestParams = buildRequest(endpoint, body);
var request = https.request(requestParams, function(response) {
var responseBody = '';
response.on('data', function(chunk) {
responseBody += chunk;
});
response.on('end', function() {
var info = JSON.parse(responseBody);
var failedItems;
var success;
if (response.statusCode >= 200 && response.statusCode < 299) {
failedItems = info.items.filter(function(x) {
return x.index.status >= 300;
});
success = {
"attemptedItems": info.items.length,
"successfulItems": info.items.length - failedItems.length,
"failedItems": failedItems.length
};
}
var error = response.statusCode !== 200 || info.errors === true ? {
"statusCode": response.statusCode,
"responseBody": responseBody
} : null;
callback(error, success, response.statusCode, failedItems);
});
}).on('error', function(e) {
callback(e);
});
request.end(requestParams.body);
}
function buildRequest(endpoint, body) {
const [ep, port] = endpoint.split(':');
return request = {
host: ep,
port: port,
method: 'PUT',
path: '/',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
},
};
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc