Git Product home page Git Product logo

sumo's Introduction

๐ŸŒ‡ As of January 2020, this module is deprecated. It is provided as-is, with no warranty. We are not accepting new bugfixes or feature requests at this time.

sumo

A Node.js SDK for Sumo Logic's Search Job API

API

createReadStream

Create a readable stream of messages or records that result from a Sumo Logic search. Messages are the raw log messages, records are the result of a search with some form of aggregation (e.g. count by _sourceCategory). Credentials can be provided explicitly, or read from environment variables: SUMO_LOGIC_ACCESS_ID and SUMO_LOGIC_ACCESS_KEY.

Parameters

  • type string one of messages or records
  • search object Sumo Logic search parameters
    • search.query string the query string
    • search.from number the starting timestamp in ms
    • search.to number the ending timestamp in ms
    • search.auth object? Sumo Logic credentials
      • search.auth.accessId string? Sumo Logic access ID
      • search.auth.accessKey string? Sumo Logic access key
  • options object readable stream options

Examples

const sumo = require('@mapbox/sumo');
const search = {
  query: '"error" | count by _sourceCategory',
  from: 1487733054071,
  to: 1487733356114,
  auth: {
    accessId: xxx,
    accessKey: xxxx
  }
};
const messages = sumo.createReadStream('messages', search);
messages.on('data', (msg) => console.log(msg));

Returns object a readable stream of messages or records

search

Perform a search limited to less than 100 results. This will return both raw messages and aggregate records where applicable. Credentials can be provided explicitly, or read from environment variables: SUMO_LOGIC_ACCESS_ID and SUMO_LOGIC_ACCESS_KEY.

Parameters

  • search object Sumo Logic search parameters
    • search.query string the query string
    • search.from number the starting timestamp in ms
    • search.to number the ending timestamp in ms
    • search.limit number? the maximum number of messages/records (optional, default 100)
    • search.auth object? Sumo Logic credentials
      • search.auth.accessId string? Sumo Logic access ID
      • search.auth.accessKey string? Sumo Logic access key
  • callback function? a function to call with the results

Examples

const sumo = require('@mapbox/sumo');
const search = {
  query: '"error" | count by _sourceCategory',
  from: 1487733054071,
  to: 1487733356114,
  auth: {
    accessId: xxx,
    accessKey: xxxx
  }
};
sumo.search(search, (err, data) => {
  if (err) throw err;
  data.messages.forEach((msg) => console.log(msg));
  data.records.forEach((rec) => console.log(rec));
});

Returns promise resolves with the results, an object with two properties, each of which are an array: .messages and .records

CLI

A CLI command is available to run Sumo Logic queries via the command line.

$ sumo --help

  Search Sumo Logic

  USAGE: sumo [OPTIONS]

  Options:
    -q, --query     the query string
    -f, --from      the starting time, defaults to 15 minutes ago
    -t, --to        the ending time, defaults to now
    -d, --duration  the amount of time to search, starting at --from
    -g, --grouped   print aggregate search results, not raw log messages
    -j, --json      when printing raw log messages, print as JSON string. Without
                    this flag, only the log message itself will print. With it,
                    all Sumo Logic fields will be provided

  Configuration:
    SUMO_LOGIC_ACCESS_ID and SUMO_LOGIC_ACCESS_KEY must be set as environment
    variables.

  Specifying times
    --from 1s = one second ago
    --from 5m = five minutes ago
    --from 2h = two hours ago
    --from 1d = one day ago

The following are required to successfully use the CLI:

  • SUMO_LOGIC_ACCESS_ID environment variable
  • SUMO_LOGIC_ACCESS_KEY environment variable
  • -q or --query flag

sumo's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sumo's Issues

Trouble with order by _messageTime clause

Trying a CLI query like

 sumo -q '_sourceCategory = my-thing | order by _messageTime asc' --from 4d

... pagination doesn't seem to work properly. It appears that each step back in time returns messages up until present, so it keeps repeat printing the most recent messages.

Unhandled Promise rejections with createReadStream

I am seeing that the code in my proof of concept using this library gets this error from node:

Unhandled promise rejection (rejection id: 2): Error: No records were found after 30s

I can't see a way to handle this rejection as a consumer of this library.
I think mapbox/sumo should handle all internal errors and propagate any relevant errors. The relevant errors should be propagated as a promise rejection for sumo.search calls and an error event for sumo.createReadStream

API throttling

I noticed some throttling messages sneaking into the console on a search with a very large number of results, along the lines of

> sumo --query '_sourceCategory = my-thing' --from 4d
{ [HTTPError: Response code 429 (Too Many Requests)]
  message: 'Response code 429 (Too Many Requests)',
  host: 'api.sumologic.com',
  hostname: 'api.sumologic.com',
  method: 'GET',
  path: '/api/v1/search/jobs/4FD8AA773A30EAD6',
  statusCode: 429,
  statusMessage: 'Too Many Requests' }

The search continued to return results.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.