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 request.You can install slumber
and flask
package using following command –
pip install slumber
pip install flask
Create HTTP Request Using Slumber
We will create HTTP request using slumber to access roles of kibana. We will add below code into api.py
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():
try:
api = slumber.API("http://localhost:5601/api", auth=(USERNAME, PASSWORD))
result = api.systems("/security/role").get()
return r.json()
except Exception as e:
print('Publish raised an exception.')
print(e.strerror)
if __name__ == '__main__':
app.run(debug = 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.
The post Consume Kibana Rest API Using Python 3 appeared first on Rest Api Example.