-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cr0wg4n/develop
update readme and examples
- Loading branch information
Showing
5 changed files
with
121 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="kibana-api", | ||
version="0.0.2", | ||
version="0.0.3", | ||
author="Mauricio Matias Conde", | ||
author_email="[email protected]", | ||
description="This is an API mapping library for Kibana API to generate visualizations and dashboards automatically", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,57 @@ | ||
from kibana_api import Dashboard, Panel, Visualization, Kibana | ||
import time | ||
import json | ||
from kibana_api import Dashboard, Panel, Visualization, Kibana, kibana | ||
import random | ||
import unittest | ||
import os | ||
|
||
URL = "http://localhost:5601" | ||
ELASTIC_DEMO_INDEX_URL = "http://localhost:9200/index_demo/_doc" | ||
USERNAME = "elastic" | ||
PASSWORD = "elastic" | ||
|
||
|
||
class mock: | ||
index_pattern_id = "" | ||
space_id = "" | ||
visualization_id = "" | ||
|
||
class TestStringMethods(unittest.TestCase): | ||
|
||
def test_ping(self): | ||
# return True | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
test = True | ||
ping = kibana.ping() # True or False | ||
self.assertEqual(ping, test) | ||
|
||
def test_url_parser(self): | ||
pass | ||
# return True | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
url = kibana.url(URL, "1", "2", "3") | ||
self.assertEqual("http://localhost:5601/1/2/3", url) | ||
|
||
def test_create_space(self): | ||
pass | ||
def test_generate_data(self): | ||
# return True | ||
data = { | ||
"@timestamp": "2021-05-26T13:40:15.000Z", | ||
"user": { | ||
"name": "matias max", | ||
"email": "[email protected]", | ||
"age": 22 | ||
} | ||
} | ||
response = Kibana(base_url=URL, username=USERNAME, password=PASSWORD).requester(url=ELASTIC_DEMO_INDEX_URL, method="post", data=json.dumps(data)) | ||
print("generated data:", response) | ||
self.assertEqual(201, response.status_code) | ||
|
||
|
||
def test1_create_space(self): | ||
# return True | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
id = f"test-{int(random.randint(0,100)*0.33)}" | ||
name = "test" + id | ||
description = "descripcion del espacio de pruebas" | ||
id = "test-{}".format(int(random.randint(0,100)*0.33)) | ||
name = id | ||
description = "space description" | ||
color = "#000000" | ||
response = kibana.space(id=id, name=name, description=description, color=color).create() | ||
response_json = { | ||
|
@@ -29,80 +61,73 @@ def test_create_space(self): | |
"color": color, | ||
"disabledFeatures": [] | ||
} | ||
mock.space_id = id | ||
print("space created: ", mock.space_id) | ||
self.assertEqual(response.json(), response_json) | ||
|
||
def test_create_index_pattern(self): | ||
pass | ||
def test2_create_index_pattern(self): | ||
# return True | ||
pattern_json = { | ||
"title":"demo*", | ||
"title":"index*", | ||
"timeFieldName": "@timestamp", | ||
"fields":"[]" | ||
} | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
res = kibana.object(space_id="demo").create('index-pattern', attribs=pattern_json) | ||
self.assertEqual(res.json()["attributes"], pattern_json) | ||
response = kibana.object(space_id=mock.space_id).create('index-pattern', attribs=pattern_json).json() | ||
mock.index_pattern_id = response["id"] | ||
print("index created: ", mock.index_pattern_id) | ||
self.assertEqual(response["attributes"], pattern_json) | ||
|
||
def test_import(self): | ||
pass | ||
def test3_import(self): | ||
# return True | ||
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
FILE_PATH = os.path.join(CURRENT_DIR, 'exported_data.ndjson') | ||
|
||
file = open(FILE_PATH, 'r') | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
response = kibana.object().loads(file=file) | ||
response = kibana.object(space_id=mock.space_id).loads(file=file) | ||
file.close() | ||
print(response.json()) | ||
print(response) | ||
|
||
def test_get_all_objects(self): | ||
pass | ||
def test4_get_all_objects(self): | ||
# return True | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
response = kibana.object(space_id="demo").all(type="index-pattern") | ||
print(response.json()) | ||
|
||
def test_create_panel(self): | ||
pass | ||
test = {'version': '7.8.0', 'gridData': {'x': 0, 'y': 12, 'w': 48, 'h': 12, 'i': 'holamundo'}, 'panelIndex': 'holamundo', 'embeddableConfig': {}, 'panelRefName': 'panel_0'} | ||
result = Panel("panel_0", 48, 12, 0, 12, id="holamundo", visualization_id="XXXXXXXXXXXX") | ||
references = result.get_reference() | ||
print(references) | ||
response = kibana.object(space_id=mock.space_id).all(type="index-pattern") | ||
print(response) | ||
|
||
def test5_create_panel(self): | ||
# return True | ||
panel_id = "XXXXX" | ||
test = {'version': '7.8.0', 'gridData': {'x': 0, 'y': 12, 'w': 48, 'h': 12, 'i': panel_id}, 'panelIndex': panel_id, 'embeddableConfig': {}, 'panelRefName': 'panel_0'} | ||
result = Panel("panel_0", 48, 12, 0, 12, id=panel_id) | ||
self.assertEqual(test, result.create()) | ||
|
||
def test_create_visualization(self): | ||
pass | ||
pattern_json = { | ||
"title":"demo*", | ||
"timeFieldName": "@timestamp", | ||
"fields":"[]" | ||
} | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
res = kibana.object(space_id="demo", attribs=pattern_json).create('index-pattern').json() | ||
index_pattern = res["id"] | ||
def test6_create_visualization(self): | ||
# return True | ||
type = "line" | ||
title = "hello this is a visualization :D 2" | ||
visualization = Visualization(type=type, title=title, index_pattern_id=index_pattern).create() | ||
res = kibana.object(space_id="demo").create('visualization', body=visualization).json() | ||
print(res) | ||
|
||
def test_create_dashboard(self): | ||
pass | ||
pattern_json = { | ||
"title":"de*", | ||
"timeFieldName": "@timestamp", | ||
"fields":"[]" | ||
} | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
res = kibana.object(space_id="demo", attribs=pattern_json).create('index-pattern').json() | ||
index_pattern = res["id"] | ||
type = "line" | ||
title = "hello this is a visualization :D 3" | ||
visualization = Visualization(type=type, title=title, index_pattern_id=index_pattern).create() | ||
res = kibana.object(space_id="demo").create('visualization', body=visualization).json() | ||
visualization_id = res["id"] | ||
panel = Panel("panel_0", 48, 12, 0, 2, visualization_id=visualization_id) | ||
visualization_obj = Visualization(type=type, title=title, index_pattern_id=mock.index_pattern_id).create() | ||
response = kibana.object(space_id=mock.space_id).create('visualization', body=visualization_obj).json() | ||
mock.visualization_id = response["id"] | ||
print("visualization created: ", mock.visualization_id) | ||
|
||
def test7_create_dashboard(self): | ||
# return True | ||
panel = Panel("panel_0", 48, 12, 0, 2, visualization_id=mock.visualization_id) | ||
panels = [panel.create()] | ||
references = [panel.get_reference()] | ||
dasboard = Dashboard(title="hola mundo", panels=panels, references=references, query="user.name: mat*").create() | ||
res = kibana.object(space_id="demo").create('dashboard', body=dasboard).json() | ||
print(res) | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
response = kibana.object(space_id=mock.space_id).create('dashboard', body=dasboard).json() | ||
dashboard_id = response["id"] | ||
print("dashboard created: ", dashboard_id) | ||
|
||
def test8_object_by_id(self): | ||
# return True | ||
kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD) | ||
reponse = kibana.object(space_id=mock.space_id).get(id=mock.visualization_id, type="visualization") | ||
print(reponse) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |