Skip to content

Commit

Permalink
Merge pull request #1 from cr0wg4n/develop
Browse files Browse the repository at this point in the history
adding demo tests
  • Loading branch information
cr0wg4n authored May 26, 2021
2 parents 453b304 + 2bcba60 commit 4b31f01
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 195 deletions.
167 changes: 88 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,89 @@ URL = "http://localhost:5601"
USERNAME = "XXXX"
PASSWORD = "XXXX"

kibana = Kibana(base_url=URL, username=USERNAME, password=PASSWORD)
```

### Create Space
```python
""
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()
```
out:
```bash
""
```

### Create Object (index-pattern)
```python
""
```
out:
```bash
""
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)
```

### Create Object (visualization)
```python
""
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).json()
```
out:
```bash
""
### Visualization Modelation
```python
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_json = visualization.create()
```
### Create Object (dashboard)

### Panel Modelation
```python
""
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_json = panel.create()
references = panel.get_references()
```
out:
```bash
""

### Create Object (dashboard)
```python
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).create()
visualization_response = kibana.object(space_id="demo").create('visualization', body=visualization).json()
visualization_id = visualization_response["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)
dashboard_response = dashboard.create()
```

### List all objects
```python
""
objects_response = kibana.object(space_id="demo").all() # All objects
print(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
print(objects_response.json())

```
out:
```bash
""

### Import Objects
```python
file = open("demo.ndjson", 'r')
response = kibana.object().loads(file=file)
file.close()
```

## Development
Expand All @@ -68,90 +108,59 @@ testing purposes):

```yaml
version: '2.2'

services:
es01:
elastic:
hostname: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
container_name: es01
container_name: elastic
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "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:
- data01:/usr/share/elasticsearch/data
- elastic_volume:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic

es02:
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic

es03:
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic

kib01:
kibana:
image: docker.elastic.co/kibana/kibana:${VERSION}
container_name: kib01
container_name: kibana
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: '["http://es01:9200","http://es02:9200","http://es03:9200"]'
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_USERNAME: ${ELASTIC_USERNAME}
ELASTICSEARCH_PASSWORD: ${ELASTIC_PASSWORD}
ADMIN_PRIVILEGES: "true"
networks:
- elastic

volumes:
data01:
driver: local
data02:
driver: local
data03:
elastic_volume:
driver: local

networks:
elastic:
driver: bridge
```
The `.env` file cointains:

```bash
VERSION=7.8.0
ELASTIC_USERNAME=elastic
ELASTIC_PASSWORD=elastic
```

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

```bash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
{
"type": "histogram",
"type": "area",
"aggs": [
{
"id": "1",
"enabled": true,
"type": "count",
"schema": "metric",
"params": {}
},
{
"id": "2",
"enabled": true,
"type": "date_histogram",
"schema": "segment",
"params": {
"field": "@timestamp",
"timeRange": {
"from": "now-1h",
"to": "now"
},
"useNormalizedEsInterval": true,
"scaleMetricValues": false,
"interval": "auto",
"drop_partials": false,
"min_doc_count": 1,
"extended_bounds": {}
}
}
],
"params": {
Expand Down Expand Up @@ -77,8 +58,8 @@
"seriesParams": [
{
"show": true,
"type": "histogram",
"mode": "normal",
"type": "area",
"mode": "stacked",
"data": {
"label": "Count",
"id": "1"
Expand All @@ -104,5 +85,5 @@
},
"labels": {}
},
"title": ""
"title": "area"
}
44 changes: 44 additions & 0 deletions kibana_api/mappings/heatmap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "heatmap",
"aggs": [
{
"id": "1",
"enabled": true,
"type": "count",
"schema": "metric",
"params": {}
}
],
"params": {
"type": "heatmap",
"addTooltip": true,
"addLegend": true,
"enableHover": false,
"legendPosition": "right",
"times": [],
"colorsNumber": 4,
"colorSchema": "Greens",
"setColorRange": false,
"colorsRange": [],
"invertColors": false,
"percentageMode": false,
"valueAxes": [
{
"show": false,
"id": "ValueAxis-1",
"type": "value",
"scale": {
"type": "linear",
"defaultYExtents": false
},
"labels": {
"show": false,
"rotate": 0,
"overwriteColor": false,
"color": "black"
}
}
]
},
"title": "heatmap"
}
Loading

0 comments on commit 4b31f01

Please sign in to comment.