Coder Social home page Coder Social logo

dgautier / kibana-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cr0wg4n/kibana-api

0.0 0.0 0.0 51 KB

This is an API mapping library to interact with objects of kibana API

Home Page: https://pypi.org/project/kibana-api/

License: MIT License

Python 99.64% Shell 0.36%

kibana-api's Introduction

Kibana API Mapping Library

Note: This unofficial library is only a proof of concept

Supported Versions Downloads

Development Requirements

I only use requests to perform HTTP requests and pure logic for all behaviour.

Installation

You can find this package in https://pypi.org/project/kibana-api/

pip install kibana-api

Usage and Examples

If you going to test every example, you should run the docker-compose.yml example(development section).

Take a note: every create action returns a <Requests> Object as a result of HTTP request

Configure Kibana Object:

URL = "http://localhost:5601"
USERNAME = "XXXX" 
PASSWORD = "XXXX"
# username and password are optional fields
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD)

Create Space

id = "demo"
name = "demo"
description = "descripcion del espacio de pruebas"
color = "#000000"
space = kibana.space(id=id, name=name, description=description, color=color)
space_response = space.create()
space_json = space_response.json()

Create Object (index-pattern)

pattern_json = {
    "title":"demo*",
    "timeFieldName": "@timestamp", #timefiledname is important, it taken as a reference to time
    "fields":"[]"
}
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD)
index_pattern_response = kibana.object(space_id="demo").create('index-pattern', attribs=pattern_json)
index_pattern_json = index_pattern.json()

Create Object (visualization)

type = "metric"
title = "Hello this is a basic metric visualization"
index_pattern_id = "XXXX-XXX-XXXX" # every visualization needs an index pattern to work
visualization = Visualization(type=type, title=title, index_pattern_id=index_pattern).create()
visualization_response = kibana.object(space_id="demo").create('visualization', body=visualization)
visualization_json = visualization_response.json()

Visualization Modelation

index_pattern = "XXXXX-XXXXXX-XXXXXX"
type = "line"
title = "Hello this is a basic line visualization"
visualization = Visualization(type=type, title=title, index_pattern_id=index_pattern)
visulization_model_json = visualization.create() # this operation returns a JSON body not a request response

Panel Modelation

width=48 
height=12
pos_x=0
pos_y=1
panel = Panel("panel_0", width, height, pos_x, pos_y, visualization_id=visualization_id)
panel_model_json = panel.create() # this operation returns a JSON body not a request response
references_model_json = panel.get_references() # this operation returns a JSON body not a request response

Create Object (dashboard)

index_pattern_id = "XXXXX-XXXXXX-XXXXXX"
type = "line"
title = "Hello this is a basic line visualization"
visualization = Visualization(type=type, title=title, index_pattern_id=index_pattern_id).create() # this operation returns a JSON body not a request response
visualization_response = kibana.object(space_id="demo").create('visualization', body=visualization)
visualization_json = visualization_response.json()
visualization_id = visualization_json["id"]

panel = Panel("panel_0", 48, 12, 0, 2, visualization_id=visualization_id)
panels = [panel.create()]
references = [panel.get_reference()]
dashboard = Dashboard(title="Demo Dashboard", panels=panels, references=references).create() # this operation returns a JSON body not a request response

dashboard_response = kibana.object(space_id=mock.space_id).create('dashboard', body=dashboard)
dashboard_json = dashboard_response.json()

List all objects

objects_response = kibana.object(space_id="demo").all() # All objects
objects_json = objects_response.json()
# Filter by types: "visualization", "dashboard", "search", "index-pattern", 
# "config", "timelion-sheet", "url", "query", "canvas-element", "canvas-workpad", "lens",
# "infrastructure-ui-source", "metrics-explorer-view", "inventory-view"
objects_response = kibana.object(space_id="demo").all(type="index-pattern") # Type in specific 
objects_json = objects_response.json()

List all spaces

spaces_response = kibana.space().all() # All spaces
spaces_json = spaces_response.json()

Import Objects

file = open("demo.ndjson", 'r')
response = kibana.object().loads(file=file)
file.close()

Development

Before starting you should run the docker-compose.yml file at tests folder (for testing purposes):

version: '2.2'

services:
  elastic:
    hostname: elasticsearch
    image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
    container_name: elastic
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
      - xpack.security.enabled=true
      - xpack.security.audit.enabled=true
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elastic_volume:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic

  kibana:
    image: docker.elastic.co/kibana/kibana:${VERSION}
    container_name: kibana
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://elasticsearch:9200
      ELASTICSEARCH_USERNAME: ${ELASTIC_USERNAME}
      ELASTICSEARCH_PASSWORD: ${ELASTIC_PASSWORD}
      ADMIN_PRIVILEGES: "true"
    networks:
      - elastic

volumes:
  elastic_volume:
    driver: local

networks:
  elastic:
    driver: bridge

The .env file cointains:

VERSION=7.8.0
ELASTIC_USERNAME=elastic
ELASTIC_PASSWORD=elastic

Once the container is up you can validate every unit test:

python -m unittest tests.tests 

Contributing

Yes fella, you know how ;)

Contact Me

My blog: cr0wg4n

Twitter: cr0wg4n

Linkedin: cr0wg4n

kibana-api's People

Contributors

cr0wg4n avatar

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.