hagen1778 / grafana-import-export

shell scripts for importing and exporting Grafana's dashboards and datasources
160 stars 62 forks source link

Wrong param error while import the json file #11

Open ghost opened 5 years ago

ghost commented 5 years ago

What grafana version i am using?

6.2.4

What i am trying?

Trying to import "my_test.json" file in grafana

what is the error i am getting?

Wrong param "/u04/monitor/dashboards/kla/dashboards/my_test.json". Must be data/{organization}/{type}/{file} Unknown type sys_monitor

What is in my config.sh? ORGS=("org1:aaa") HOST="http://rhsappnb:3000" FILE_DIR=/u04/monitor/dashboards

what is in my importer.sh?

No changes

ghost commented 5 years ago

Note: I am trying to import the json file which is not exists in grafana

vaibhavsonivs commented 4 years ago

same issue i am also getting please help us to come out from this ASPS, need urge tn help

Aminechakr commented 4 years ago

Any feedbacks on this issue ?

tonkotsurobot commented 4 years ago

So, I managed to get the importer going with a few hacks, I will do a PR once I know of a nicer way to do it. Workaround steps:

  1. The script assumes a directory level that is too deep On line 54 of importer.sh, modify "ARGS=(${FILE_DIR}/*/*/*.json)" to be "ARGS=(${FILE_DIR}/*/*.json)"
  2. The script also assumes that your dashboard directory is set at the root of the OS. So move your exported files so that they have the following structure /ORG/dashboards /ORG/datasources /ORG/alert-notifications

Doing both of the above allow me to export/import grafana data from one instance to the other on grafana 7

jmorcar commented 3 years ago

I had to change the import command to

cat $FILE | jq '. * {overwrite: true }' | curl --fail -k -X$HTTP_VERB \
         -H "Content-Type: application/json" \
         -H "Accept: application/json" \
         -H "Authorization: Basic $KEY" \
         -d @- \
         $URL

Only to import dashboards is OK, with datasource import the before command is failed...

If try to use the curl command XPUT or XPOST implementation of this repository aswell, but not working when datasource already exist...

So I investigate commands with jq to try solve it without success:

Example manual commands with failed result: result: {"message":"Failed to update datasource. Reload new version and try again"}

WITHOUT JQ {overwrite: true } - json datasource exported without changes:

$ cat "VSPP/datasources/VSPP.json.json" | curl -k -XPUT -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Basic aaaaaaaa" http://localhost:3000/api/datasources/VSPP.json -d @- result: {"message":"Failed to update datasource. Reload new version and try again"}

Any idea about how to import datasources ??? I try to import from export json files like (when datasource already exist - I need update the version of datasource or overwrite it )

{
  "id": 39,
  "orgId": 6,
  "name": "VSPP",
  "type": "graphite",
  "typeLogoUrl": "",
  "access": "proxy",
  "url": "http://1.1.1.1:8066",
  "password": "",
  "user": "",
  "database": "",
  "basicAuth": true,
  "basicAuthUser": "***",
  "basicAuthPassword": "****",
  "withCredentials": false,
  "isDefault": true,
  "jsonData": {
    "graphiteVersion": "",
    "keepCookies": []
  },
  "secureJsonFields": {},
  "version": 5,
  "readOnly": false
}
jmorcar commented 3 years ago

I investigate the error ... https://sourcegraph.com/github.com/grafana/grafana@00e7c7c4b725ed7249e15a3eaac3043fda1d9f68/-/blob/pkg/api/datasources.go

err = bus.Dispatch(&cmd)
--
  | if err != nil {
  | if err == m.ErrDataSourceUpdatingOldVersion {
  | return Error(500, "Failed to update datasource. Reload new version and try again", err)
  | }
  | return Error(500, "Failed to update datasource", err)
  | }

So I suspect the version of data source is older in the destination grafana db .. I will try to increase version with a sed command to all datasource json files exported to solve that problem.