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

@clickandmortar/kibana-url-builder

v0.7.2

Published

Kibana URL builder

Downloads

3,807

Readme

Kibana URL builder

This library allows building Kibana URLs, for instance when sending notifications.

:warning: Generated Kibana URLs have currently been tested on Kibana 6.x only.

Usage

# Using npm
npm install @clickandmortar/kibana-url-builder

# Using Yarn
yarn add @clickandmortar/kibana-url-builder
const kub = require('@clickandmortar/kibana-url-builder')

const url = kub.buildDiscoverUrl({
    host: 'http://kibana:5601',
    columns: ['_source'],
    filters: [],
    query: 'my query'
})

// url = http://kibana:5601/app/kibana#/discover?_g=(time:(from:now-15m,mode:quick,to:now))&_a=(columns:!(_source),filters:!(),interval:auto,query:(language:lucene,query:'my query'),sort:!('@timestamp',desc))

Methods

buildDiscoverUrl ({ host, refreshInterval, period, columns, filters, index, interval, query, sort }: KibanaDiscoverUrlBuildParameters): string

This method returns a stateless Kibana "Discover" URL, which can be shared and used by anyone having access to the Kibana instance.

| Parameter | Type | Default | Required | Example | |---|---|---|---|---| | host | string | | ✅ | http://kibana:5601 | | columns | string[] | ['_source'] | | ['_source', 'log'] | | filters | KibanaQueryFilter[] | [] | | See below | | query | string | | | foo AND bar (Lucene syntax) | | period | KibanaQueryPeriod | { "from": "now-15m", "mode": "quick", "to": "now" } | | See below | | index | string | | When using filters | my-index-pattern | | interval | string | auto | | 15m | | refreshInterval | KibanaQueryRefreshInterval | { "pause": true, "value": 300000 } | | | | sort | KibanaQuerySort | { "field": "@timestamp", "direction": "desc" } | | |

Filters

When using filters, you must provide the index pattern name using index property.

Supported filter types:

  • Exists / Not exists (type = exists)
  • Is / Is not (type = query)
  • One of / Not one of (type = phrases)
  • Between / Not between (type = range)

"Not" filters can be used setting the negate property of the filter to true.

All filters are of type KibanaQueryFilter and share the following properties:

| Property | Type | Default | Required | Description | |---|---|---|---|---| | type | string | - | ✅ | See below examples | | field | string | - | ✅ | Name of the ES field | | value | string|boolean|number|string[] | - | ✅ | See below examples | | negate | boolean | false | - | Negate the filter | | alias | string | none | | Alias for the filter | | disabled | boolean | false | | Mark filter as disabled |

Exists / Not exists
{
  type: 'exists',
  field: 'statusCode'
}
Is / Is not
{
  type: 'query',
  field: 'namespace',
  value: 'kube-system'
}
One of / Not one of
{
  type: 'phrases',
  field: 'namespace',
  value: ['kube-system', 'default']
}
Between / Not between
{
  type: 'range',
  field: 'statusCode',
  value: [400, 499]
}

Period

Three period presets are available:

Quick & Relative periods
{
  from: 'now-7d',
  to: 'now',
  mode: 'quick'
}
Absolute periods
{
  from: '2021-03-31T22:00:00.000Z',
  to: '2021-04-02T21:59:59.999Z',
  mode: 'absolute'
}

Testing

npm run test

Enhancements

  • [x] Add support for filters
  • [ ] Add tests: ⚙️ WIP
  • [x] Add missing filters: is one of, is between
  • [x] Add documentation for filters
  • [x] Add documentation for advanced period
  • [ ] Add support for Visualize query