Plugins: Return jsondetails as an json object instead of raw json on datasource healthchecks. (#22859)

This commit is contained in:
Carl Bergquist 2020-03-18 12:08:52 +01:00 committed by GitHub
parent 60e3437fc1
commit 579abad9cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package api
import (
"encoding/json"
"sort"
"github.com/grafana/grafana/pkg/api/dtos"
@ -385,10 +386,22 @@ func (hs *HTTPServer) CheckDatasourceHealth(c *models.ReqContext) {
return
}
var jsonDetails map[string]interface{}
payload := map[string]interface{}{
"status": resp.Status.String(),
"message": resp.Message,
"jsonDetails": resp.JSONDetails,
"status": resp.Status.String(),
"message": resp.Message,
"details": jsonDetails,
}
// Unmarshal JSONDetails if it's not empty.
if len(resp.JSONDetails) > 0 {
err = json.Unmarshal(resp.JSONDetails, &jsonDetails)
if err != nil {
c.JsonApiErr(500, "Failed to unmarshal detailed response from backend plugin", err)
return
}
payload["details"] = jsonDetails
}
if resp.Status != backendplugin.HealthStatusOk {