|
@@ -3,6 +3,8 @@ package grafana
|
3
|
3
|
import (
|
4
|
4
|
"encoding/json"
|
5
|
5
|
"fmt"
|
|
6
|
+
|
|
7
|
+ "grafana/helpers"
|
6
|
8
|
)
|
7
|
9
|
|
8
|
10
|
// dbSearchResponse represents an element of the response to a dashboard search
|
|
@@ -129,12 +131,9 @@ func (c *Client) GetDashboard(URI string) (db *Dashboard, err error) {
|
129
|
131
|
// existing one. The Grafana API decides whether to create or update based on the
|
130
|
132
|
// "id" attribute in the dashboard's JSON: If it's unkown or null, it's a
|
131
|
133
|
// creation, else it's an update.
|
132
|
|
-// The slug is only used for error reporting, and can differ from the
|
133
|
|
-// dashboard's actual slug in its JSON content. However, it's recommended to use
|
134
|
|
-// the same in both places.
|
135
|
134
|
// Returns an error if there was an issue generating the request body, performing
|
136
|
135
|
// the request or decoding the response's body.
|
137
|
|
-func (c *Client) CreateOrUpdateDashboard(slug string, contentJSON []byte) (err error) {
|
|
136
|
+func (c *Client) CreateOrUpdateDashboard(contentJSON []byte) (err error) {
|
138
|
137
|
reqBody := dbCreateOrUpdateRequest{
|
139
|
138
|
Dashboard: rawJSON(contentJSON),
|
140
|
139
|
Overwrite: true,
|
|
@@ -161,6 +160,11 @@ func (c *Client) CreateOrUpdateDashboard(slug string, contentJSON []byte) (err e
|
161
|
160
|
return
|
162
|
161
|
}
|
163
|
162
|
|
|
163
|
+ slug, err := helpers.GetDashboardSlug(contentJSON)
|
|
164
|
+ if err != nil {
|
|
165
|
+ return
|
|
166
|
+ }
|
|
167
|
+
|
164
|
168
|
if respBody.Status != "success" && isHttpUnknownError {
|
165
|
169
|
return fmt.Errorf(
|
166
|
170
|
"Failed to update dashboard %s (%d %s): %s",
|