Importing Dashboard via CURL fails with 500 error

On my old dev stack I used the beats setup feature to install the example dashboards. That ended up with a bunch I will never use. So now that I'm building an actual test stack, I want to pick and choose which dashboards I import.

I started with this on: https://github.com/elastic/beats/blob/v7.6.2/metricbeat/module/system/_meta/kibana/7/dashboard/Metricbeat-host-overview.json

I found the docs on how to import and tried it out.

The response:

{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}

In Kibana's logs:

testelk01_kibana | {"type":"error","@timestamp":"2020-04-29T11:17:53-07:00","tags":[],"pid":6,"level":"error","error":{"message":"Failure attempting to migrate saved object 'Network Traffic (Packets) [Metricbeat System] ECS' - SyntaxError: Unexpected token o in JSON at position 1","name":"Error","stack":"Error: Failure attempting to migrate saved object 'Network Traffic (Packets) [Metricbeat System] ECS' - SyntaxError: Unexpected token o in JSON at position 1\n    at 7.0.0 (/usr/share/kibana/src/legacy/core_plugins/kibana/migrations/migrations.js:605:15)\n    at tryTransformDoc (/usr/share/kibana/src/core/server/saved_objects/migrations/core/document_migrator.js:213:22)\n    at migrateProp (/usr/share/kibana/src/core/server/saved_objects/migrations/core/document_migrator.js:270:11)\n    at applyMigrations (/usr/share/kibana/src/core/server/saved_objects/migrations/core/document_migrator.js:172:11)\n    at DocumentMigrator.transformAndValidate [as transformDoc] (/usr/share/kibana/src/core/server/saved_objects/migrations/core/document_migrator.js:151:43)\n    at DocumentMigrator.doc [as migrate] (/usr/share/kibana/src/core/server/saved_objects/migrations/core/document_migrator.js:47:19)\n    at KibanaMigrator.migrateDocument (/usr/share/kibana/src/core/server/saved_objects/migrations/kibana/kibana_migrator.js:139:34)\n    at objects.map.object (/usr/share/kibana/src/core/server/saved_objects/service/lib/repository.js:233:74)\n    at Array.map (<anonymous>)\n    at SavedObjectsRepository.bulkCreate (/usr/share/kibana/src/core/server/saved_objects/service/lib/repository.js:217:37)\n    at SavedObjectsClient.bulkCreate (/usr/share/kibana/src/core/server/saved_objects/service/saved_objects_client.js:46:35)\n    at EncryptedSavedObjectsClientWrapper.bulkCreate (/usr/share/kibana/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.js:80:89)\n    at process._tickCallback (internal/process/next_tick.js:68:7)"},"url":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":{},"pathname":"/api/kibana/dashboards/import","path":"/api/kibana/dashboards/import","href":"/api/kibana/dashboards/import"},"message":"Failure attempting to migrate saved object 'Network Traffic (Packets) [Metricbeat System] ECS' - SyntaxError: Unexpected token o in JSON at position 1"}

Since I didn't anything like it in the documentation example, I removed this from the end of the dashboard json:

,
    "version": "6.0.0-rc1-SNAPSHOT"

Still ended up with the same error.

My curl command, ran on the same server as Kibana. Removed the dashboard json due to Discourse character limits.

curl -X POST "http://adminusername:password@localhost:5601/api/kibana/dashboards/import" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
< json of the dashboard, modified as I mentioned above >
'

What am I missing?

Is there a UI option for importing that I just haven't found?

Thanks.

Please follow the steps in our documentation to install the dashboard using Metricbeat itself.

That isn't what I want to do. I only want to install the specific dashboards I will use. Using beats setup will not do that.

I could just push them all in, then figure out how to delete the ones I don't use.

I'd still like to figure out how to push via the import api, especially if I find non-Elastic created dashboards to import. :slight_smile:

The files cannot imported as-is, as they're pre-processed by Metricbeat.

This is the procedure which works and it's the "official" one:

  1. Grab Metricbeat 7.6.2
  2. Go to the kibana/7/dashboard directory
  3. Move all the files of the dashboards you do not want in a sub directory
  4. Run, depending on your OS, the following command:
   ./metricbeat setup --dashboards \
-E 'setup.dashboards.enabled=true' \
-E 'setup.kibana.host=https://<kibana host>:<kibana port>' \
-E 'setup.kibana.username=elastic' \
-E 'setup.kibana.password=<password>' \
-E 'output.elasticsearch.enabled=false' \
-E 'output.console.enabled=true'

You can pass other parameters (see here and here)

The command you're using is correct, but it seems the dashboards we have bundled with Beats are pre-processed by the Beat binary.

To import:

curl -s -XPOST https://<kibana:port>/api/kibana/dashboards/import -d "@dashboard.json" -u elastic:password -Hkbn-xsrf:true -Hcontent-type:application/json

To export:

curl -s https://<kibana:port>/api/kibana/dashboards/export?dashboard=<dashboard-id> -u elastic:password -o dashboard.json

Ah. Well, so much for my idea of picking and choosing...

Thanks. I'll do it the official way.