This tutorial help to consume kibana api using python.We will use python flask framework to access kibana api. The Kibana api help to access some features outside the box.The Kibana API clearly marked as either stable, beta, or experimental.

The kibana is based on elastic search, They are providing some of the features via a REST API, which is ideal for people that want to create an integration with Kibana or that want to automate certain aspects of configuring and deploying Kibana.

Kibana Role Management API Using Python3

We will access all user roles , This API is experimental and may be changed or removed completely in a future release. The role-based access control is stable, but the APIs for managing the roles are currently experimental.

The role management API allows people to manage roles that grant Kibana privileges. The user must have manage_security cluster privilege.

We will install Python dependency

We will use slumber package to handle HTTP requests. You can install slumber and flask package using the following command –]

pip install slumber
pip install flask

Create HTTP Request Using Slumber

We will create an HTTP request using slumber to access roles of kibana. We will add the below code into file.

from flask import Flask
from flask_restful import Resource, Api
from flask_cors import CORS
import slumber
app = Flask(__name__)
CORS(app) ## To allow direct AJAX calls
@app.route('/getRoles', methods=['GET'])
def home():
api = slumber.API("http://localhost:5601/api", auth=(USERNAME, PASSWORD))
result ="/security/role").get()
return r.json()
except Exception as e:
print('Publish raised an exception.')
if __name__ == '__main__': = True)

A successful call returns a response code of 200 and a response body containing a JSON representation of the roles.

Basic Authentication requires an Authorization header with the username and API token in the username:password format encoded as Base64.

Genislab Technologies

NexGeneration complete end-2-end software testing & modern development operations tooling & solutions

Do you want to discuss your testing requirements with us? please don’t hesitate to hit the contact us button below, and we will get back to you at our earliest..