Просмотр исходного кода

fix(alerting): adds support for basic auth

closes #5897
bergquist 9 лет назад
Родитель
Сommit
c0697b99d6
2 измененных файлов с 17 добавлено и 6 удалено
  1. 10 4
      pkg/services/alerting/conditions/query.go
  2. 7 2
      pkg/tsdb/graphite/graphite.go

+ 10 - 4
pkg/services/alerting/conditions/query.go

@@ -106,10 +106,16 @@ func (c *QueryCondition) getRequestForAlertRule(datasource *m.DataSource) *tsdb.
 				RefId: "A",
 				Query: c.Query.Model.Get("target").MustString(),
 				DataSource: &tsdb.DataSourceInfo{
-					Id:       datasource.Id,
-					Name:     datasource.Name,
-					PluginId: datasource.Type,
-					Url:      datasource.Url,
+					Id:                datasource.Id,
+					Name:              datasource.Name,
+					PluginId:          datasource.Type,
+					Url:               datasource.Url,
+					User:              datasource.User,
+					Password:          datasource.Password,
+					Database:          datasource.Database,
+					BasicAuth:         datasource.BasicAuth,
+					BasicAuthUser:     datasource.BasicAuthUser,
+					BasicAuthPassword: datasource.BasicAuthPassword,
 				},
 			},
 		},

+ 7 - 2
pkg/tsdb/graphite/graphite.go

@@ -43,12 +43,17 @@ func (e *GraphiteExecutor) Execute(queries tsdb.QuerySlice, context *tsdb.QueryC
 	}
 
 	client := http.Client{Timeout: time.Duration(10 * time.Second)}
-	res, err := client.PostForm(e.Url+"/render?", params)
+	req, _ := http.NewRequest(http.MethodPost, e.Url+"/render?", strings.NewReader(params.Encode()))
+	if e.BasicAuth {
+		req.SetBasicAuth("carl", "carl")
+	}
+
+	res, err := client.Do(req)
+	defer res.Body.Close()
 	if err != nil {
 		result.Error = err
 		return result
 	}
-	defer res.Body.Close()
 
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {