SHARE
TWEET

Untitled

a guest Jan 21st, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Zlib = require('zlib');
  2. const Logstash = require('logstash-client');
  3.  
  4. exports.handler = async (event, context) => {
  5.   const logstashClient = new Logstash({
  6.         type: 'udp',
  7.         host: process.env.LOGSTASH_HOST,
  8.         port: process.env.LOGSTASH_PORT
  9.   });
  10.   event.Records.forEach(record => {
  11.       const payload = new Buffer(record.kinesis.data, 'base64');
  12.       const json = (Zlib.gunzipSync(payload)).toString('utf8');
  13. const Zlib = require('zlib');
  14. const Logstash = require('logstash-client');
  15.  
  16. const lambdaVersion = function (logStream) {
  17.     let start = logStream.indexOf('[')
  18.     let end = logStream.indexOf(']')
  19.     return logStream.substring(start+1, end)
  20. }
  21.  
  22. exports.handler = async (event, context) => {
  23.   const logstashClient = new Logstash({
  24.         type: 'udp',
  25.         host: process.env.LOGSTASH_HOST,
  26.         port: process.env.LOGSTASH_PORT
  27.   });
  28.   event.Records.forEach(record => {
  29.       const payload = new Buffer(record.kinesis.data, 'base64');
  30.       const json = (Zlib.gunzipSync(payload)).toString('utf8');
  31.       const data = JSON.parse(json)
  32.  
  33.       const functionName = data.logGroup.split('/').reverse()[0]
  34.       const functionVersion = lambdaVersion(data.logStream)
  35.  
  36.       data.logEvents.forEach((event) => {
  37.         if (!(event.message.startsWith('START RequestId') ||
  38.             event.message.startsWith('END RequestId') ||
  39.             event.message.startsWith('REPORT RequestId'))) {
  40.           logstashClient.send({
  41.               message: event.extractedFields.event,
  42.               function: functionName,
  43.               version: functionVersion,
  44.           })
  45.         }
  46.       })
  47.   })
  48.   return 'done';
  49. }
  50.       JSON.parse(json).logEvents.forEach((event) => {
  51.           logstashClient.send(JSON.parse(event.extractedFields.event))
  52.       })
  53.   })
  54.   return 'done';
  55. }
  56.  
  57. const Zlib = require('zlib');
  58. const Logstash = require('logstash-client');
  59.  
  60. const lambdaVersion = function (logStream) {
  61.     let start = logStream.indexOf('[')
  62.     let end = logStream.indexOf(']')
  63.     return logStream.substring(start+1, end)
  64. }
  65.  
  66. exports.handler = async (event, context) => {
  67.   const logstashClient = new Logstash({
  68.         type: 'udp',
  69.         host: process.env.LOGSTASH_HOST,
  70.         port: process.env.LOGSTASH_PORT
  71.   });
  72.   event.Records.forEach(record => {
  73.       const payload = new Buffer(record.kinesis.data, 'base64');
  74.       const json = (Zlib.gunzipSync(payload)).toString('utf8');
  75.       const data = JSON.parse(json)
  76.  
  77.       const functionName = data.logGroup.split('/').reverse()[0]
  78.       const functionVersion = lambdaVersion(data.logStream)
  79.  
  80.       data.logEvents.forEach((event) => {
  81.         console.log('ok')
  82.         console.log(event)
  83.         if (!(event.message.startsWith('START RequestId') ||
  84.             event.message.startsWith('END RequestId') ||
  85.             event.message.startsWith('REPORT RequestId'))) {
  86.           logstashClient.send({
  87.               message: event.extractedFields.event,
  88.               function: functionName,
  89.               version: functionVersion,
  90.           })
  91.         }
  92.       })
  93.   })
  94.   return 'done';
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top