feat: added service filtering for kibana dashboard

master
Sven Ketelsen 4 years ago
parent 40e0a44043
commit 05a6f8a67f

@ -126,14 +126,16 @@
- actions - actions
- osquery - osquery
- savedObjectsTagging - savedObjectsTagging
es_indexpattern_name: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-*' es_index_pattern_tenant: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-*'
es_index_pattern_service: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-*-{{ cluster_service }}-*'
es_search_name: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-{{ cluster_service }}' es_search_name: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-{{ cluster_service }}'
es_dashboard_name: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-{{ cluster_service }}' es_dashboard_name: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-{{ cluster_service }}'
es_container_name: '{{ stage }}-{{ tenant_id }}-{{ cluster_name }}-01-{{ cluster_service }}'
tasks: tasks:
- name: "Do some stuff in elastic with spaces ... " - name: "Do some stuff in elastic with spaces ... "
include_role: include_role:
name: elastic name: kibana
tasks_from: _configure_spaces.yml tasks_from: _configure_spaces.yml
apply: apply:
tags: tags:
@ -144,9 +146,9 @@
tags: tags:
- es-spaces - es-spaces
- name: "Do some stuff in elastic with roles ... " - name: "Do some stuff in elastic with roles ..."
include_role: include_role:
name: elastic name: kibana
tasks_from: _configure_roles.yml tasks_from: _configure_roles.yml
apply: apply:
tags: tags:
@ -157,9 +159,9 @@
tags: tags:
- es-roles - es-roles
- name: "Do some stuff in elastic with users ... " - name: "Do some stuff in elastic with users ..."
include_role: include_role:
name: elastic name: kibana
tasks_from: _configure_users.yml tasks_from: _configure_users.yml
apply: apply:
tags: tags:
@ -170,9 +172,9 @@
tags: tags:
- es-users - es-users
- name: "Do some stuff in elastic with spaces ... " - name: "Do some stuff in elastic with spaces ..."
include_role: include_role:
name: elastic name: kibana
tasks_from: _import_savedobjects.yml tasks_from: _import_savedobjects.yml
apply: apply:
tags: tags:
@ -180,12 +182,13 @@
vars: vars:
es_space: *es_space_name es_space: *es_space_name
es_indexpattern_title: '{{ es_indexpattern_name }}' es_indexpattern_title: '{{ es_indexpattern_name }}'
es_indexpattern_uuid: '{{ es_indexpattern_name | to_uuid }}' es_index_pattern_tenant_uuid: '{{ es_index_pattern_tenant | to_uuid }}'
es_index_pattern_service_uuid: '{{ es_index_pattern_service | to_uuid }}'
es_search_title: '{{ es_search_name }}' es_search_title: '{{ es_search_name }}'
es_search_uuid: '{{ es_search_name | to_uuid }}' es_search_uuid: '{{ es_search_name | to_uuid }}'
es_panel_uuid: "{{ 'panel_' + es_dashboard_name | to_uuid }}" es_panel_uuid: "{{ 'panel_' + es_dashboard_name | to_uuid }}"
es_dashboard_title: '{{ es_dashboard_name }}' es_dashboard_title: '{{ es_dashboard_name }}'
es_dashboard_uuid: '{{ es_dashboard_name | to_uuid }}' es_dashboard_uuid: '{{ es_dashboard_name | to_uuid }}'
tags: tags:
- es-importobjects - es-importobjects

@ -1,3 +0,0 @@
{"attributes":{"fieldAttrs":"{\"message_full\":{\"count\":1}}","fields":"[]","runtimeFieldMap":"{}","timeFieldName":"@timestamp","title":"{{ es_indexpattern_title }}","typeMeta":"{}"},"coreMigrationVersion":"7.16.1","id":"{{ es_indexpattern_uuid }}","migrationVersion":{"index-pattern":"7.11.0"},"references":[],"type":"index-pattern"}
{"attributes":{"columns":["message_full"],"description":"","grid":{},"hideChart":false,"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"},"sort":[["@timestamp","desc"]],"title":"{{ es_search_title }}"},"coreMigrationVersion":"7.16.1","id":"{{ es_search_uuid }}","migrationVersion":{"search":"7.9.3"},"references":[{"id":"{{ es_indexpattern_uuid }}","name":"kibanaSavedObjectMeta.searchSourceJSON.index","type":"index-pattern"}],"type":"search"}
{"attributes":{"description":"","hits":0,"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[]}"},"optionsJSON":"{\"useMargins\":true,\"syncColors\":false,\"hidePanelTitles\":false}","panelsJSON":"[{\"version\":\"7.16.1\",\"type\":\"search\",\"gridData\":{\"x\":0,\"y\":0,\"w\":50,\"h\":50,\"i\":\"{{ es_panel_uuid }}\"},\"panelIndex\":\"{{ es_panel_uuid }}\",\"embeddableConfig\":{\"enhancements\":{}},\"panelRefName\":\"panel_{{ es_panel_uuid }}\"}]","timeRestore":false,"title":"{{ es_dashboard_title }}","version":1},"coreMigrationVersion":"7.16.1","id":"{{ es_dashboard_uuid }}","migrationVersion":{"dashboard":"7.16.0"},"references":[{"id":"{{ es_search_uuid }}","name":"{{ es_panel_uuid }}:panel_{{ es_panel_uuid }}","type":"search"}],"type":"dashboard"}

@ -2,3 +2,7 @@
kibana_image_name: "docker.elastic.co/kibana/kibana" kibana_image_name: "docker.elastic.co/kibana/kibana"
kibana_image_version: "7.16.1" kibana_image_version: "7.16.1"
kibana_advanced_settings:
changes:
truncate:maxHeight: 0

@ -46,7 +46,7 @@
url: "https://{{ api_endpoint }}/s/{{ es_space }}/api/saved_objects/_find?per_page=10000&type=search" url: "https://{{ api_endpoint }}/s/{{ es_space }}/api/saved_objects/_find?per_page=10000&type=search"
method: GET method: GET
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
register: all_searches register: all_searches
@ -84,7 +84,7 @@
name: '{{ panelindex_uuid }}' name: '{{ panelindex_uuid }}'
delegate_to: localhost delegate_to: localhost
type: 'search' type: 'search'
id: '{{ lookup_search_object[0].id }}' id: '{{ lookup_search_object[0].id }}'
when: when:
- lookup_search_object | length > 0 - lookup_search_object | length > 0
when: when:
@ -107,16 +107,13 @@
- debug: - debug:
msg: 'DEBUG elastic_dashboard_cleaned: {{ elastic_dashboard_cleaned }}' msg: 'DEBUG elastic_dashboard_cleaned: {{ elastic_dashboard_cleaned }}'
- name: "Create {{ es_object_type }} <<{{ elastic_dashboard.attributes.title }}>>" - name: "Create {{ es_object_type }} <<{{ elastic_dashboard.attributes.title }}>>"
delegate_to: localhost delegate_to: localhost
uri: uri:
url: "https://{{ api_endpoint }}{{ api_path }}/{{ es_object_type }}" url: "https://{{ api_endpoint }}{{ api_path }}/{{ es_object_type }}"
method: POST method: POST
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
headers: headers:
@ -135,7 +132,7 @@
url: 'https://{{ api_endpoint }}{{ api_path }}/{{ es_object_type }}/{{ lookup_dashboard_object[0]["id"] }}' url: 'https://{{ api_endpoint }}{{ api_path }}/{{ es_object_type }}/{{ lookup_dashboard_object[0]["id"] }}'
method: PUT method: PUT
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
headers: headers:
@ -154,7 +151,7 @@
url: 'https://{{ api_endpoint }}{{ api_path }}/{{ es_object_type }}/{{ lookup_dashboard_object[0]["id"] }}' url: 'https://{{ api_endpoint }}{{ api_path }}/{{ es_object_type }}/{{ lookup_dashboard_object[0]["id"] }}'
method: DELETE method: DELETE
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
headers: headers:

@ -10,14 +10,14 @@
url: "https://{{ api_endpoint }}{{ api_path }}" url: "https://{{ api_endpoint }}{{ api_path }}"
method: GET method: GET
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
register: all_spaces register: all_spaces
become: false become: false
- set_fact: - set_fact:
lookup_space_object: '{{ all_spaces.json | community.general.json_query(spaces_query) }}' lookup_space_object: "{{ all_spaces.json | community.general.json_query(spaces_query) }}"
vars: vars:
spaces_query: "[?name=='{{ elastic_space.name }}']" spaces_query: "[?name=='{{ elastic_space.name }}']"
@ -28,12 +28,12 @@
- set_fact: - set_fact:
elastic_space_cleaned: "{{ elastic_space_cleaned | combine({item.key: item.value}) }}" elastic_space_cleaned: "{{ elastic_space_cleaned | combine({item.key: item.value}) }}"
with_dict: '{{ elastic_space }}' with_dict: "{{ elastic_space }}"
when: when:
- item.key not in ['elastic_state'] - item.key not in ['elastic_state']
- debug: - debug:
msg: '{{ lookup_space_object | to_json }}' msg: "{{ lookup_space_object | to_json }}"
- name: "Create space <<{{ elastic_space.name }}>>" - name: "Create space <<{{ elastic_space.name }}>>"
delegate_to: localhost delegate_to: localhost
@ -41,7 +41,7 @@
url: "https://{{ api_endpoint }}{{ api_path }}" url: "https://{{ api_endpoint }}{{ api_path }}"
method: POST method: POST
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
headers: headers:
@ -60,7 +60,7 @@
url: "https://{{ api_endpoint }}{{ api_path }}/{{ elastic_space.name }}" url: "https://{{ api_endpoint }}{{ api_path }}/{{ elastic_space.name }}"
method: PUT method: PUT
status_code: [200] status_code: [200]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
headers: headers:
@ -73,13 +73,32 @@
- space_exists - space_exists
- elastic_space.elastic_state == 'present' - elastic_space.elastic_state == 'present'
- name: "Update space advanced settings <<{{ elastic_space.name }}>>"
delegate_to: localhost
uri:
url: "https://{{ api_endpoint }}/s/{{ elastic_space.name }}/api/kibana/settings"
method: POST
status_code: [200]
user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes
headers:
Content-Type: application/json
kbn-xsrf: true
body_format: json
body: '{{ kibana_advanced_settings | to_json }}'
become: false
when:
- space_exists
- elastic_space.elastic_state == 'present'
- name: "DELETE space <<{{ elastic_space.name }}>>" - name: "DELETE space <<{{ elastic_space.name }}>>"
delegate_to: localhost delegate_to: localhost
uri: uri:
url: "https://{{ api_endpoint }}{{ api_path }}/{{ elastic_space.name }}" url: "https://{{ api_endpoint }}{{ api_path }}/{{ elastic_space.name }}"
method: DELETE method: DELETE
status_code: [204] status_code: [204]
user: "{{ elastic_admin_username_vault }}" user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}" password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes force_basic_auth: yes
headers: headers:

@ -2,10 +2,13 @@
- set_fact: - set_fact:
api_path: '/s/{{ es_space }}/api/saved_objects' api_path: '/s/{{ es_space }}/api/saved_objects'
- name: "Import smardigo default dashboard and its related objects (index-pattern,search)" - name: "Import smardigo default dashboard and its related objects (index-pattern,search,...)"
delegate_to: localhost delegate_to: localhost
set_fact: set_fact:
es_import_objects: "{{ lookup('template','smardigo_default_objects.json.j2') }}" es_object_smardigo_index_pattern_tenant: "{{ lookup('template','smardigo_index_pattern_tenant.json.j2') }}"
es_object_smardigo_index_pattern_service: "{{ lookup('template','smardigo_index_pattern_service.json.j2') }}"
es_object_smardigo_search: "{{ lookup('template','smardigo_search.json.j2') }}"
es_object_smardigo_dashboard: "{{ lookup('template','smardigo_dashboard.json.j2') }}"
when: when:
- elastic_state == 'present' - elastic_state == 'present'
@ -13,7 +16,11 @@
delegate_to: localhost delegate_to: localhost
copy: copy:
dest: '/tmp/es_objects_ready_to_import__objects.ndjson' dest: '/tmp/es_objects_ready_to_import__objects.ndjson'
content: '{{ es_import_objects }}' content: |
{{ es_object_smardigo_index_pattern_tenant | to_json(separators=(',',':')) }}
{{ es_object_smardigo_index_pattern_service | to_json(separators=(',',':')) }}
{{ es_object_smardigo_search | to_json(separators=(',',':')) }}
{{ es_object_smardigo_dashboard | to_json(separators=(',',':')) }}
when: when:
- elastic_state == 'present' - elastic_state == 'present'
@ -45,7 +52,6 @@
when: when:
- elastic_state == 'present' - elastic_state == 'present'
- name: "Set default indexpattern ..." - name: "Set default indexpattern ..."
delegate_to: localhost delegate_to: localhost
uri: uri:
@ -60,7 +66,7 @@
body_format: json body_format: json
body: body:
changes: changes:
defaultIndex: '{{ es_indexpattern_uuid }}' defaultIndex: '{{ es_index_pattern_tenant_uuid }}'
become: false become: false
when: when:
- elastic_state == 'present' - elastic_state == 'present'

@ -0,0 +1,25 @@
{
"attributes" : {
"description" : "",
"hits" : 0,
"kibanaSavedObjectMeta" : {
"searchSourceJSON" : "{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[]}"
},
"optionsJSON" : "{\"useMargins\":true,\"syncColors\":false,\"hidePanelTitles\":false}",
"panelsJSON" : "[{\"version\":\"7.16.1\",\"type\":\"search\",\"gridData\":{\"x\":0,\"y\":0,\"w\":50,\"h\":50,\"i\":\"{{ es_panel_uuid }}\"},\"panelIndex\":\"{{ es_panel_uuid }}\",\"embeddableConfig\":{\"enhancements\":{}},\"panelRefName\":\"panel_{{ es_panel_uuid }}\"}]",
"timeRestore" : false,
"title" : "{{ es_dashboard_title }}",
"version" : 1
},
"coreMigrationVersion" : "7.16.1",
"id" : "{{ es_dashboard_uuid }}",
"migrationVersion" : {
"dashboard" : "7.16.0"
},
"references" : [ {
"id" : "{{ es_search_uuid }}",
"name" : "{{ es_panel_uuid }}:panel_{{ es_panel_uuid }}",
"type" : "search"
} ],
"type" : "dashboard"
}

@ -0,0 +1,17 @@
{
"attributes" : {
"fieldAttrs" : "{\"message_full\":{\"count\":1}}",
"fields" : "[]",
"runtimeFieldMap" : "{}",
"timeFieldName" : "@timestamp",
"title" : "{{ es_index_pattern_service }}",
"typeMeta" : "{}"
},
"coreMigrationVersion" : "7.16.1",
"id" : "{{ es_index_pattern_service_uuid }}",
"migrationVersion" : {
"index-pattern" : "7.11.0"
},
"references" : [ ],
"type" : "index-pattern"
}

@ -0,0 +1,17 @@
{
"attributes" : {
"fieldAttrs" : "{\"message_full\":{\"count\":1}}",
"fields" : "[]",
"runtimeFieldMap" : "{}",
"timeFieldName" : "@timestamp",
"title" : "{{ es_index_pattern_tenant }}",
"typeMeta" : "{}"
},
"coreMigrationVersion" : "7.16.1",
"id" : "{{ es_index_pattern_tenant_uuid }}",
"migrationVersion" : {
"index-pattern" : "7.11.0"
},
"references" : [ ],
"type" : "index-pattern"
}

@ -0,0 +1,26 @@
{
"attributes" : {
"columns" : [ "message_full" ],
"description" : "",
"grid" : {
},
"hideChart" : false,
"kibanaSavedObjectMeta" : {
"searchSourceJSON" : "{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[{\"meta\":{\"alias\":null,\"negate\":false,\"disabled\":false,\"type\":\"phrase\",\"key\":\"container.name\",\"params\":{\"query\":\"{{ es_container_name }}\"}},\"query\":{\"match_phrase\":{\"container.name\":\"{{ es_container_name }}\"}},\"$state\":{\"store\":\"appState\"}}],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
},
"sort" : [ [ "@timestamp",
"desc" ] ],
"title" : "{{ es_search_title }}"
},
"coreMigrationVersion" : "7.16.1",
"id" : "{{ es_search_uuid }}",
"migrationVersion" : {
"search" : "7.9.3"
},
"references" : [ {
"id" : "{{ es_index_pattern_service_uuid }}",
"name" : "kibanaSavedObjectMeta.searchSourceJSON.index",
"type" : "index-pattern"
} ],
"type" : "search"
}
Loading…
Cancel
Save