# nssl-kibana

> Edit static lookup for kibana index-pattern dynamically

Latest version **0.0.2** (published 2019-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install nssl-kibana
pnpm add nssl-kibana
yarn add nssl-kibana
bun add nssl-kibana
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-05-22 |
| First published | 2019-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 91.5 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | agix |
| Maintainers | agix |
| Keywords | kibana, static lookup, index-pattern, index pattern |

## Links

- npm: https://www.npmjs.com/package/nssl-kibana
- Repository: https://github.com/agix/not-so-static-lookup-kibana
- Homepage: https://github.com/agix/not-so-static-lookup-kibana#readme
- Issues: https://github.com/agix/not-so-static-lookup-kibana/issues
- npm.io page: https://npm.io/package/nssl-kibana

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) ^7.0.0

## Recent versions

- 0.0.2 (latest) — 2019-05-22
- 0.0.1 — 2019-05-22

## 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://<your-kibana-url>:5601/app/kibana#/management/kibana/index_patterns/

---
_Source: https://npm.io/package/nssl-kibana · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
