src/index.js
/**
 * Translates a CloudWatch message into a format appropriate for submitting to the Scalyr addEvents API endpoint.
 *
 * @param cloudWatchMessage   Incoming CloudWatch message.
 * @returns {Object}          Outgoing Scalyr message.
 */
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr addEvents API endpoint.
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr addEvents API endpoint .
function transformToAddEventsMessage(cloudWatchMessage) {
  let sessionOpts = logGroupOptions[cloudWatchMessage.logGroup] || {};
  let defaultSession = {
    'serverHost': defaultServerHost || `cloudwatch-${cloudWatchMessage.owner}`,
    'logfile': cloudWatchMessage.logGroup,
    'parser': defaultParserName
  };
  return {
    'token': decryptedScalyrApiKey,
    'session': cloudWatchMessage.logStream,
    'sessionInfo': Object.assign(defaultSession, sessionOpts),
    'events': cloudWatchMessage.logEvents.map((cloudWatchEvent) => {
      return {
        'ts': `${cloudWatchEvent.timestamp}000000`,
        'type': 0,
        'sev': 3,
        'attrs': {
          'cwStream': cloudWatchMessage.logStream,
          'cwId': cloudWatchEvent.id,
          'message': cloudWatchEvent.message
        }
      };
    })
  };
}
function transformToAddEventsMessage ( cloudWatchMessage ) { let sessionOpts = logGroupOptions [ cloudWatchMessage . logGroup ] || { } ; let defaultSession = { 'serverHost' : defaultServerHost || ` ${ cloudWatchMessage . owner } ` , 'logfile' : cloudWatchMessage . logGroup , 'parser' : defaultParserName } ; return { 'token' : decryptedScalyrApiKey , 'session' : cloudWatchMessage . logStream , 'sessionInfo' : Object . assign ( defaultSession , sessionOpts ) , 'events' : cloudWatchMessage . logEvents . map ( ( cloudWatchEvent ) => { return { 'ts' : ` ${ cloudWatchEvent . timestamp } ` , 'type' : 0 , 'sev' : 3 , 'attrs' : { 'cwStream' : cloudWatchMessage . logStream , 'cwId' : cloudWatchEvent . id , 'message' : cloudWatchEvent . message } } ; } ) } ; }
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr addEvents API endpoint.
Translates a CloudWatch message into a format appropriate for submitting to the Scalyr addEvents API endpoint .
// TODO make changes here if you want to parse in AWS Lambda before sending to Scalyr