npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alertlogic/al-collector-js

v3.0.14

Published

Alert Logic Collector Common Library

Downloads

6,362

Readme

al-collector-js

Build Status ALPS build

Alert Logic cloud collector common library.

Overview

This repository contains the common JavaScript functions used by Node.js collectors in the cloud.

HOWTO consume this library in Node.js

To install:

npm install --save @alertlogic/al-collector-js

and in your file:

const {
    AimsC,
    AlServiceC,
    IngestC,
    AzcollectC,
    EndpointsC,
    AlLog,
    Parse ,
    RestServiceClient,
    CollectorStatusC
} = require('@alertlogic/al-collector-js');

API

AimsC

  • @param {string} apiEndpoint - Alert Logic API hostname
  • @param {Object} aimsCreds - Alert Logic API credentials.
  • @param {string} [aimsCreds.access_key_id] - Alert Logic API access key id.
  • @param {string} [aimsCreds.secret_key] - Alert Logic API secret key.
  • @param {string} cacheDir(optional) - Cache directory. defaults to '/tmp'
  • @param {Object} retryOptions(optional) - Retry Options.
const aimsClient = new AimsC(endPoint, aimsCredsi, cacheDir, retryOption);

AlServiceC

  • @param {string} apiEndpoint - Alert Logic API hostname.
  • @param {string} name - Alert Logic service name.
  • @param {string} version - Alert Logic service HTTP API version.
  • @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
  • @param {Object} retryOptions(optional) - Retry Options.
const alServiceClient = new AlServiceC(apiEndpoint, name, version, aimsCreds, retryOptions);

IngestC

  • @param {string} apiEndpoint - Alert Logic API hostname.
  • @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
  • @param {string} [aimsCreds.access_key_id] - Alert Logic API access key id.
  • @param {string} [aimsCreds.secret_key] - Alert Logic API secret key.
  • @param {string} functionType(optional) - Function type. Defaults to 'lambda_function'
  • @param {Object} retryOptions(optional) - Retry Options.
const alIngestClient = new IngestC(apiEndpoint, aimsCreds, functionType, retryOption);

AzcollectC

  • @param {string} apiEndpoint - Alert Logic API hostname
  • @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
  • @param {string} [aimsCreds.access_key_id] - Aert Logic API access key id.
  • @param {string} [aimsCreds.secret_key] - Alert Logic API secret key.
  • @param {string} collectorType - Al collector type: cwl, cwe, o365 etc
  • @param {boolean} sendCheckinCompressed - Whether to compress checkin payload
  • @param {Object} retryOptions(optional) - Retry Options.
const azCollectClient = new AzcollectC(apiEndpoint, aimsCreds, collectorType, sendCheckinCompressed, retryOptions);

EndpointsC

  • @param {string} apiEndpoint - Alert Logic API hostname.
  • @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
  • @param {string} [aimsCreds.access_key_id] - Alert Logic API access key id.
  • @param {string} [aimsCreds.secret_key] - Alert Logic API secret key.
  • @param {Object} retryOptions(optional) - Retry Options.
const alEndpointsClient = EndpointsC(apiEndpoint, aimsCreds, retryOption);

CollectorStatusC

  • @param {string} apiEndpoint - Alert Logic API hostname.
  • @param {Object} aimsCreds - Alert Logic API credentials object, refer to AimsC.
  • @param {*} retryOptions.
const alCollectorStatusClient = CollectorStatusC(apiEndpoint, aimsCreds, retryOption);

AlLog

  • @param hostId - host uuid obtained at collector registration
  • @param sourceId - source/collector id obtained at collector registration
  • @param hostmetaElems - a list of hostmeta JSON objects. For example,
  var hostTypeElem = {
      key: 'host_type',
      value: {str: 'azure_fun'}
  };
  var localHostnameElem = {
      key: 'local_hostname',
      value: {str: process.env.WEBSITE_HOSTNAME}
  };

  var hostmetaElems = [hostTypeElem, localHostnameElem];

Consult 'metadata' definition in ./proto/host_metadata.piqi.proto

  • @param content - a list of log messages to be ingested. Content should be batched on the caller level.
  • @param parseCallback(message) - a function to parse a log message into a JSON object which is converted into protobuf. The parse callback is expected to construct the following object out of each log message:
  var parsedMessage = {
      messageTs: 1542138053,
      priority: 11,
      progName: 'o365webhook',
      pid: undefined,
      message: 'some message string',
      messageType: 'json/azure.o365',
      messageTypeId: 'AzureActiveDirectory',
      messageTsUs: undefined
  };

Consult 'collected_message' definition in proto/common_proto.piqi.proto @param callback

@return callback - (error, builtPayload, payloadSize) @NOTE: Batch size should be tweaked on a caller level in order to avoid "Maximum payload size exceeded" errors. For an Azure function consult eventHub.maxBatchSize property in host.json. For an AWS Lambda via kinesis trigger batch size configuration.

Parse

getMsgTs

Get timestamp from Azure management API event. Returns the first match from the paths array. Returns the current timestamp if none of the paths are found.

  • @param {object}message - an Azure managment API event message
  • @param {Array(string)}paths - an array of possible timestamp paths(dot-delimeted). e.g. "foo.bar"
  • @return {object}time
  • @return {number} [time.sec] - timestamp in seconds
  • @return {number | null} [time.usec] - timestamp in microseconds

getMsgTypeId

Get the message Type ID of an Azure management API event message.

  • @param {object}message - an Azure managment API event message
  • @param {Array(string)}paths - an array of possible timestamp paths(dot-delimeted). e.g. "foo.bar"
  • @param {string}defaultValue(optional) - The value if none of the paths are found. Defaults to null.

Compiling proto

You will need pbjs tool in order to compile protobuf definitions located in proto:

npm install -g protobufjs
make pb-clean
make pb

Debugging

To get a debug trace, set an Node.js environment variable called DEBUG and specify the JavaScript module/s to debug.

E.g.

export DEBUG=*
export DEBUG=index

Or set an environment variable called "DEBUG" in your AWS stack (using the AWS console) for the "alertlogic-cwe-collector" AWS Lambda function, with value "index" or "*".

See debug for further details.

Known Issues/ Open Questions

  • TBD.

Useful Links