Browse Source

Add Content-Type header for non-GET HTTP requests + rename function for more accuracy

Brendan Abolivier 6 years ago
parent
commit
a353eb97b1
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
3 changed files with 6 additions and 2 deletions
  1. 4
    0
      src/grafana/client.go
  2. 1
    1
      src/grafana/dashboards.go
  3. 1
    1
      src/pusher/webhook.go

+ 4
- 0
src/grafana/client.go View File

37
 	authHeader := fmt.Sprintf("Bearer %s", c.APIKey)
37
 	authHeader := fmt.Sprintf("Bearer %s", c.APIKey)
38
 	req.Header.Add("Authorization", authHeader)
38
 	req.Header.Add("Authorization", authHeader)
39
 
39
 
40
+	if method != "GET" {
41
+		req.Header.Add("Content-Type", "application/json")
42
+	}
43
+
40
 	resp, err := c.httpClient.Do(req)
44
 	resp, err := c.httpClient.Do(req)
41
 	if err != nil {
45
 	if err != nil {
42
 		return nil, err
46
 		return nil, err

+ 1
- 1
src/grafana/dashboards.go View File

77
 	return
77
 	return
78
 }
78
 }
79
 
79
 
80
-func (c *Client) UpdateDashboard(slug string, contentJSON []byte) (err error) {
80
+func (c *Client) CreateOrUpdateDashboard(slug string, contentJSON []byte) (err error) {
81
 	reqBody := dbUpdateRequest{
81
 	reqBody := dbUpdateRequest{
82
 		Dashboard: rawJSON(contentJSON),
82
 		Dashboard: rawJSON(contentJSON),
83
 		Overwrite: false,
83
 		Overwrite: false,

+ 1
- 1
src/pusher/webhook.go View File

73
 	// Remove the .json part
73
 	// Remove the .json part
74
 	slug := strings.Split(filename, ".json")[0]
74
 	slug := strings.Split(filename, ".json")[0]
75
 
75
 
76
-	return grafanaClient.UpdateDashboard(slug, fileContent)
76
+	return grafanaClient.CreateOrUpdateDashboard(slug, fileContent)
77
 }
77
 }