Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the import/export dashboards scripts to dev-tools #1359

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha1...master[Check the HEAD d
==== Breaking changes

*Affecting all Beats*
- Add scripts for managing the dashboards of a single Beat {pull}1359[1359]

*Packetbeat*

Expand Down
11 changes: 11 additions & 0 deletions dev-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ Other scripts:
|----------------------|-------------|
| aggregate_coverage.py | Used to create coverage reports that contain both unit and system tests data |
| merge_pr | Used to make it easier to open a PR that merges one branch into another. |


Import / export the dashboards of a single Beat:

| File | Description |
|-----------------------|-------------|
| import_dashboards.sh | Bash script to import the Beat dashboards from a local directory in Elasticsearch |
| import_dashboards.ps1 | Powershell script to import the Beat dashboards from a local directory in Elasticsearch |
| export_dashboards.py | Python script to export the Beat dashboards from Elasticsearch to a local directory|


Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def ExportVisualization(es, visualization, kibana_index, output_directory):
search,
kibana_index,
output_directory)
else:
print("Missing savedSearchId from {}".format(doc["_source"]))


def ExportSearch(es, search, kibana_index, output_directory):
Expand Down Expand Up @@ -115,8 +113,8 @@ def main():
help="Elasticsearch index for the Kibana dashboards. "
"E.g. .kibana",
default=".kibana")
parser.add_argument("--dir", help="Output directory",
default="saved")
parser.add_argument("--dir", help="Output directory. E.g. output",
default="output")

args = parser.parse_args()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ param(
[String] $d, [String] $dir,
[switch] $h = $false, [switch] $help = $false
)
function prompt { "$pwd\" }

# The default value of the variable. Initialize your own variables here
$ELASTICSEARCH="http://localhost:9200"
$CURL="Invoke-RestMethod"
$KIBANA_INDEX=".kibana"
$SCRIPT=$MyInvocation.MyCommand.Name
$KIBANA_DIR=
$KIBANA_DIR=prompt

# Verify that Invoke-RestMethod is present. It was added in PS 3.
if (!(Get-Command $CURL -errorAction SilentlyContinue))
Expand All @@ -33,6 +34,7 @@ Options:
Print the help menu.
-d | -dir
Local directory where the dashboards, visualizations, searches and index pattern are saved.
By default is $KIBANA_DIR.
-l | -url
Elasticseacrh URL. By default is $ELASTICSEARCH.
-u | -user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
ELASTICSEARCH=http://localhost:9200
CURL=curl
KIBANA_INDEX=".kibana"
DIR=
DIR=.

print_usage() {
echo "

Load the dashboards, visualizations and index patterns into the given
Elasticsearch instance.
Import the dashboards, visualizations and index patterns into Kibana.

The Kibana dashboards together with its dependencies are saved into a
special index pattern in Elasticsearch (by default .kibana), so you need to
specify the Elasticsearch URL and optionally an username and password.

Usage:
$(basename "$0") -url ${ELASTICSEARCH} -user admin:secret -index ${KIBANA_INDEX}
Expand All @@ -26,6 +29,7 @@ Options:
Print the help menu.
-d | -dir
Local directory where the dashboards, visualizations, searches and index pattern are saved.
By default is current directory.
-l | -url
Elasticseacrh URL. By default is ${ELASTICSEARCH}.
-u | -user
Expand Down
2 changes: 2 additions & 0 deletions libbeat/docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ include::./dashboards.asciidoc[]

include::./newbeat.asciidoc[]

include::./newdashboards.asciidoc[]

include::./release.asciidoc[]
154 changes: 154 additions & 0 deletions libbeat/docs/newdashboards.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
[[new-dashboards]]
== Developer Guide: Creating new Kibana dashboards

This guide walks you through the steps for creating a new Kibana dashboards
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should recommend here to use the virtual environment under testing/environments to create the dashboards. The reasons for this is:

  • People start with an empty Kibana instance
  • Everyone is using the same Kibana version (most recent one)
  • No setup on developer side needed

This should lead to hopefully cleaner dashboards or outdated dashboards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I will add it.

or changing the existing Kibana dashboards for a single Beat.

If the Beat you are targeting has already few dashboards, the first step would be to import
those dashboards to Kibana and then start changing or adding a dashboard from the existing ones.

Kibana saves the dashboards together with all the dependencies (visualizations, searches and
index patterns) in a special index in Elasticsearch. By default the index is `.kibana`, but it can be changed to anything.

After you have created or changed a dashboard in Kibana for a certain Beat, you can export it together with all dependencies to
your local directory.

We recommend you use the virtual environment under
https://github.com/elastic/beats/tree/master/testing/environments[beats/testing/environments] with the latest version of
Kibana and Elasticsearch to import, create and export the Kibana dashboards, so the latest dashboards are exported from
the same Kibana version.

=== Import existing Beat dashboards

For Unix systems, you can use the bash script `import_dashboards.sh`
and for Windows you can use the powershell script `import_dashboards.ps1` from
https://github.com/elastic/beats/tree/master/dev-tools[dev-tools].

The command has the following options:

[source,shell]
----------------------------------------------------------------------
$ ./import_dashboards.sh -h


Import the dashboards, visualizations and index patterns into Kibana.

The Kibana dashboards together with its dependencies are saved into a
special index pattern in Elasticsearch (by default .kibana), so you need to
specify the Elasticsearch URL and optionally an username and password.

Usage:
import_dashboards.sh -url http://localhost:9200 -user admin:secret -index .kibana

Options:
-h | -help
Print the help menu.
-d | -dir
Local directory where the dashboards, visualizations, searches and index
pattern are saved.
-l | -url
Elasticseacrh URL. By default is http://localhost:9200.
-u | -user
Username and password for authenticating to Elasticsearch using Basic
Authentication. The username and password should be separated by a
colon (i.e. admin:secret). By default no username and password are
used.
-i | -index
Kibana index pattern where to save the dashboards, visualizations,
index patterns. By default is .kibana.

----------------------------------------------------------------------

==== dir
The input directory with the dashboards together with its dependencies. The default value is current directory.

==== url
The Elasticsearch URL. The default value is http://localhost:9200.

==== user
The username and password for authenticating the connection to Elasticsearch using Basic Authentication. The username and password should be separated by a colon. By default no username and password are used.

==== kibana
The Elasticsearch index pattern where Kibana saved its configuration. The default value is `.kibana`.


To import all the dashboards together with all the dependencies (visualizations, searches and index patterns), you just
need to run the following command in the beats repository:

On Unix systems:

[source,shell]
----------------------------------------------------------------------
../dev-tools/import_dashboards.sh -dir etc/kibana
----------------------------------------------------------------------

On Windows systems:

[source,shell]
----------------------------------------------------------------------
..\dev-tools\import_dashboards.ps1 -dir .\etc\kibana
----------------------------------------------------------------------


=== Export the Beat dashboards

To export all the dashboards for a Beat together with all dependencies (visualizations, searches and index patterns),
you can use the python script `export_dashboards.py` from
https://github.com/elastic/beats/tree/master/dev-tools[dev-tools].

The command has the following options:

[source,shell]
----------------------------------------------------------------------
$ python export_dashboards.py -h
usage: export_dashboards.py [-h] [--url URL] --beat BEAT [--index INDEX]
[--kibana KIBANA] [--dir DIR]

Export the Kibana dashboards together with all used visualizations, searches
and index pattern

optional arguments:
-h, --help Show this help message and exit
--url URL Elasticsearch URL. E.g. http://localhost:9200
--beat BEAT Beat name e.g. topbeat
--index INDEX Elasticsearch index for the Beat data. E.g. topbeat-*
--kibana KIBANA Elasticsearch index for the Kibana dashboards. E.g. .kibana
--dir DIR Output directory. E.g. output

----------------------------------------------------------------------

==== url
The Elasticsearch URL. The default value is http://localhost:9200.

==== beat
The name of the Beat. This argument is required.

==== index
The Elasticsearch index pattern where the Beat is storing the data. The default value is constructed from the Beat name + `-*` string.

==== kibana
The Elasticsearch index pattern where Kibana saved its configuration. The default value is `.kibana`.

==== dir
The output directory where to save the dashboards together with its dependencies. The default value is `output`.

For example to export all Packetbeat dashboards, you can run the following command in the `packetbeat` repository:

[source,shell]
----------------------------------------------------------------------
../dev-tools/export_dashboards.py --beat packetbeat
----------------------------------------------------------------------

NOTE:: We have made it even easier for you to import and export the dashboards
by running the following commands in the Beats repository:

[source,shell]
----------------------------------------------------------------------
make import-dashboards
----------------------------------------------------------------------

[source,shell]
----------------------------------------------------------------------
make export-dashboards
----------------------------------------------------------------------

21 changes: 0 additions & 21 deletions libbeat/etc/kibana/search/Default-Search.json

This file was deleted.

10 changes: 0 additions & 10 deletions libbeat/etc/kibana/visualization/Navigation.json

This file was deleted.

11 changes: 5 additions & 6 deletions libbeat/scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,15 @@ update:
bash ${ES_BEATS}/libbeat/scripts/update.sh ${BEATNAME} ${BEAT_DIR}/${BEATNAME} ${ES_BEATS}/libbeat

### KIBANA FILES HANDLING ###
ES_URL?=http://localhost:9200/

KIBANA_ES?=http://localhost:9200/
.PHONY: update
kibana-export:
python ${ES_BEATS}/libbeat/scripts/kibana_export.py --url ${KIBANA_ES} --dir $(shell pwd)/etc/kibana --beat ${BEATNAME}
export-dashboards:
python ${ES_BEATS}/dev-tools//export_dashboards.py --url ${ES_URL} --dir $(shell pwd)/etc/kibana --beat ${BEATNAME}

.PHONY: update
kibana-import:
python ${ES_BEATS}/libbeat/scripts/kibana_import.py --url ${KIBANA_ES} --dir $(shell pwd)/etc/kibana

import-dashboards:
bash ${ES_BEATS}/dev-tools/import_dashboards.sh -url ${ES_URL} -dir $(shell pwd)/etc/kibana

### CONTAINER ENVIRONMENT ####

Expand Down
47 changes: 0 additions & 47 deletions libbeat/scripts/kibana_import.py

This file was deleted.