🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

elasticsearch-nodejs-watcher

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elasticsearch-nodejs-watcher

Elasticsearch Watcher runned with Node. Alternative for X-Pack.

1.0.1
Source
npm
Version published
Maintainers
1
Created
Source

Elasticsearch NodeJS Watcher

This is alternative to Elasticsearch X-Pack Watcher.

Example usage - asking Elasticsearch each 30s if any new document that matches query appeared. It's import that schedule is each 30s and timestamp is now-30s. This blocks appearing already matched documents in new call.

const elasticWatcher = require("elastic-watcher");

const connection = {
    host: 'http://localhost:9200',
    log: 'trace'
};

const watcher = {
    schedule: "*/30 * * * * *",
    query: {
        index: 'logstash-*',
        body: {
            query: {
                bool: {
                    must: {match: {loglevel: "ERROR"}},
                    filter: {
                        range: {"@timestamp": {gte: "now-30s"}}
                    }
                }
            }
        }
    },
    predicate: ({hits: {total}}) => total > 0,
    action: () => console.log('Action!!!'),
    errorHandler: err => console.log('Oh no!!!')
};

elasticWatcher.schedule(connection, watcher);

Watcher configuration

  • Schedule is telling watcher when it needs to call Elasticsearch Values are provided in cron notation.
  • Query is Elasticsearch's query object. Use it like in Elasticsearch Watcher.
  • Predicate is same as Elasticsearch Condition. It checks if action should be executed.
  • Action is task which will be executed when predicate returns true. Action is executed within Schedule.
  • Error handler (optional) can be used to handle errors from Elasticsearch.

Elasticsearch connection configuration

Check out Elasticsearch.js documentation

License

MIT.

FAQs

Package last updated on 16 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts