Giter Site home page Giter Site logo

cribl-api's Introduction

Description

The Cribl-API service provides on-demand monitoring of various unix-based servers without having to log into each individual machine and opening up the log files found in /var/log.

Design

The REST API exposes /lines endpoint.

It accepts 3 query parameters:

filename: {String} Text representing the filename (or relative path) to a log file in /var/log
filter: {String} Text to filter the log file(s) by (ENV variable controls the MIN/MAX_FILTER_LIMIT)
limit: {number} number of matching entries to retrieve within the log (ENV variables control the MIN and MAX_LIMIT)

The API checks for the existence of the log file, and performes what's essentially known as 'tail'.

We expect the results to be ordered chronologically by event datetime, with newest events returned at the top.

Efficient solution doesn't read the (potentially) very large log file into memory. Instead, we perform byte reads using offset, and a limited buffer.

The buffer size is equal to the size of the file block, or the remaining bytes to read.

Extra challenge

In this case, it's important to determine how the nested results should be handled

Primary server runs as an aggregator. Each secondary server sends a POST request to the primary server's /subscribe endpoint.

When a REST GET /lines is received by the primary server, it sends subsequent REST GET lines request the to the secondary servers (stored in memory).

Finally, the primary server, returnes JSON Object with information about the secondary UID, filename, filter, limit, and lines (array of strings).

Usage

Server (primary)

build primary server docker image:

cd server
docker build --build-arg PRIMARY_PORT=3002 -t cribl-primary .

run primary server docker container:

docker run -p 3002:3002 --network="host" -d cribl-primary node src/primary.js

Server (secondary #1)

build secondary server docker image:

cd server
docker build --build-arg PRIMARY_PORT=3002 --build-arg SECONDARY_PORT=3003 -t cribl-secondary1 .

run secondary server docker container:

docker run -p 3003:3003 --network="host" -d cribl-secondary1 node src/secondary.js

Server (secondary #2)

build secondary server docker image:

cd server
docker build --build-arg PRIMARY_PORT=3002 --build-arg SECONDARY_PORT=3004 -t cribl-secondary2 .

run secondary server docker container:

docker run -p 3004:3004 --network="host" -d cribl-secondary2 node src/secondary.js

Client (unfinished)

build docker image: docker build -t cribl-client ./client

run docker image: docker run -p 3001:3001 cribl-client

Testing

There are at least 3 ways to test the REST API:

CURL (preferred)

You may curl the api using query parameters. Example:

curl localhost:3002/lines?filename={filename}&filter={filter}&limit={limit}

Tested cases

Valid:

http://localhost:3002/lines?filename=logs&filter=libmagick&limit=5
http://localhost:3002/lines?filename=logs&filter=libmagick&limit=50
http://localhost:3002/lines?filename=logs&filter=libmagick
http://localhost:3002/lines?filename=logs&limit=50
http://localhost:3002/lines?filename=access.log&filter=dockerd&limit=5
http://localhost:3002/lines?filename=test.log&filter=Fedora&limit=15
Invalid:

http://localhost:3002/lines?filename=syslog&filter=libmagick&limit=5 (invalid filename)
http://localhost:3002/lines?filename=dpkg.log&filter=libmagick&limit=5s0 (invalid limit)

Script

There is a test script in test directory. The scripts tests a few scenarios:

  • Wrong input types/values
  • Missing query parameters
  • Multiple filenames, filters, limits

Execute it by running: node test.js

UI (unfinished)

With the client, and server docker containers running, access the localhost at port 3001 (default). Enter filename, filter, and limit in the form input fields, and hit Fetch Logs. The results will be displayed in the scrollable div.

cribl-api's People

Contributors

elluck91 avatar

Watchers

 avatar  avatar

Forkers

jkheadley

cribl-api's Issues

Simplify docker instructions

docker instructions are a bit confusing -

  1. -p flag is redundant with --network=host, also seems like there's some problems running with -net=host on mac, could we simplify that to use a docker-compose file?
  2. possible to split primary/secondary to have their own dockerfile? doesnt look like they're sharing any code
  3. can we make PORT a runtime parameter as opposed to build time?
  4. can we avoid passing node src/primary.js to the container? each container should ideally know what to execute and only runtime parameters need to be passed in

Tests are busted

Hey Lukasz,

Thanks for submitting the final version! both the test directories seem to be blowing up, could you take a look? Also would be good to consolidate and update the instructions in README

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.