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

nssl-kibana

v0.0.2

Published

Edit static lookup for kibana index-pattern dynamically

Downloads

2

Readme

not-so-static-lookup-kibana

Kibana string static lookup table (https://cinhtau.net/2018/08/27/static-lookup/) is a good way to make your logs more readable without indexing useless text.

This library try to reduce the "static" part by allowing setting this lookup table programmatically.

Kibana or Elasticsearch adapter

Each function take as last parameter an optional Connection option (default to elasticsearch 7.10 client on http://localhost:9200 (or NSSLKIBANA_ES_URL env) with .kibana index).

You can instead pass your own elasticsearch client with different version and change the index to whatever kibana index is.

const nsslKibana = require('nssl-kibana');
const { Client } = require('@elastic/elasticsearch');
const esClient = new Client({
  node: 'http://localhost:9200',
});

(async () => {
  const indexPatternContent = await nsslKibana.getIndexPattern('logstash-*', {client: esClient});
})()

If you prefer to communicate via kibana api, you can pass an axiosInstance as a client.

const nsslKibana = require('nssl-kibana');
const axios = require('axios');

const axiosInstance =  axios.create({
  baseURL: 'http://127.0.0.1:5601/',
  timeout: 5000,
  headers: {
    'Content-Type': 'application/json',
    'kbn-xsrf': 'nssl-kibana',
    'Authorization': 'Bearer my-super-secret',
  },
});

(async () => {
  const indexPatternContent = await nsslKibana.getIndexPattern('logstash-*', {client: axiosInstance});
})()

If you specify a string as client, it will try to connect to kibana api on http://localhost:9200 (or NSSLKIBANA_KIBANA_URL env)

Methods

getIndexPattern

Straight forward function which take indexPattern name and return indexPatternContent.

Format is {id, attributes}.

id is the id of the index-pattern document and attributes are specific to index-pattern kibana saved-objects.

setIndexPattern

Straight forward function which take indexPatternContent object (as returned by getIndexPattern) and set it in kibana.

setStaticLookup

This function takes an indexPattern name, a fieldName and an array of lookupEntry ({key, value})

If the field exists as a string in the index-pattern, the lookupEntries array is set as static lookup for this field.

pushStaticLookup

Instead of setting the third parameter as the new lookupEntries for the fieldName, it adds each lookup entry ({key, value}) in the existent lookup.

If key already exists, the old value is replaced.

refreshIndexPattern

Only works for kibana adapter for now (throw UnsupportedFunctionError for es adapter).

It works on existent index-pattern only, and refresh it as if you clicked on the Refresh fields list button on http://:5601/app/kibana#/management/kibana/index_patterns/