2016-12-22 13:40:14 +01:00
|
|
|
package beater
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2016-12-30 13:32:56 +01:00
|
|
|
"errors"
|
2016-12-22 13:40:14 +01:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/elastic/beats/libbeat/logp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func requestURL(bt *Icingabeat, method, path string) (*http.Response, error) {
|
|
|
|
transport := &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
|
|
}
|
|
|
|
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: transport,
|
|
|
|
}
|
|
|
|
|
2016-12-30 14:44:23 +01:00
|
|
|
url := fmt.Sprintf(
|
|
|
|
"https://%s:%v%s",
|
|
|
|
bt.config.Host,
|
|
|
|
bt.config.Port,
|
|
|
|
path)
|
2016-12-22 13:40:14 +01:00
|
|
|
request, err := http.NewRequest(method, url, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
2016-12-30 13:32:56 +01:00
|
|
|
logp.Info("Request: %v", err)
|
2016-12-22 13:40:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
request.Header.Add("Accept", "application/json")
|
|
|
|
request.SetBasicAuth(bt.config.User, bt.config.Password)
|
|
|
|
response, err := client.Do(request)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-12-30 13:32:56 +01:00
|
|
|
switch response.StatusCode {
|
|
|
|
case 401:
|
|
|
|
err = errors.New("Authentication failed for user " + bt.config.User)
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:40:14 +01:00
|
|
|
return response, err
|
|
|
|
}
|