From ea483c0ce19c46ffa09ee6a63c356c6b54a323fb Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Wed, 18 Mar 2020 12:08:52 +0100 Subject: [PATCH] Plugins: Return jsondetails as an json object instead of raw json on datasource healthchecks. (#22859) (cherry picked from commit 579abad9cc2059767ccc5c3b9d7d432731934cd8) --- pkg/api/datasources.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index 3a75c5343f6..1f59541dc4c 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -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 {