Package: kibana-api
Kibana API Mapping LibraryDevelopment RequirementsI only userequeststo perform HTTP requests and pure logic for
all behaviour.InstallationYou can find this package inhttps://pypi.org/project/kibana-api/pipinstallkibana-apiUsage and ExamplesIf you going to test every example, you should run thedocker-compose.ymlexample(development section).Take a note: everycreateaction returns a<Requests>Object as a result of HTTP requestConfigure Kibana Object:URL="http://localhost:5601"USERNAME="XXXX"PASSWORD="XXXX"# username and password are optional fieldskibana=Kibana(base_url=URL,username=USERNAME,password=PASSWORD)Create Spaceid="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 workvisualization=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 Modelationindex_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 responsePanel Modelationwidth=48height=12pos_x=0pos_y=1panel=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 responsereferences_model_json=panel.get_references()# this operation returns a JSON body not a request responseCreate 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 responsevisualization_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 responsedashboard_response=kibana.object(space_id=mock.space_id).create('dashboard',body=dashboard)dashboard_json=dashboard_response.json()List all objectsobjects_response=kibana.object(space_id="demo").all()# All objectsobjects_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 specificobjects_json=objects_response.json()List all spacesspaces_response=kibana.space().all()# All spacesspaces_json=spaces_response.json()Import Objectsfile=open("demo.ndjson",'r')response=kibana.object().loads(file=file)file.close()DevelopmentBefore starting you should run thedocker-compose.ymlfile attestsfolder (for
testing purposes):version:'2.2'services:elastic:hostname:elasticsearchimage:docker.elastic.co/elasticsearch/elasticsearch:${VERSION}container_name:elasticenvironment:-"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:-1hard:-1volumes:-elastic_volume:/usr/share/elasticsearch/dataports:-9200:9200networks:-elastickibana:image:docker.elastic.co/kibana/kibana:${VERSION}container_name:kibanaports:-5601:5601environment:ELASTICSEARCH_URL:http://elasticsearch:9200ELASTICSEARCH_USERNAME:${ELASTIC_USERNAME}ELASTICSEARCH_PASSWORD:${ELASTIC_PASSWORD}ADMIN_PRIVILEGES:"true"networks:-elasticvolumes:elastic_volume:driver:localnetworks:elastic:driver:bridgeThe.envfile cointains:VERSION=7.8.0ELASTIC_USERNAME=elasticELASTIC_PASSWORD=elasticOnce the container is up you can validate every unit test:python-munittesttests.testsContributingYes fella, you know how ;)Contact MeMy blog:cr0wg4nTwitter:cr0wg4nLinkedin:cr0wg4n