From: Brian Brazil Date: Sun, 6 Sep 2015 06:57:59 +0000 (+0100) Subject: Make http method configurable X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c29621d927078590d59c2c9c988fffaf9d7d91a7;p=blackbox_exporter.git Make http method configurable --- diff --git a/README.md b/README.md index f71628d..ff5d75d 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,16 @@ will return metrics for a HTTP probe against google.com. A configuration showing all options is below: ``` modules: - http2xx: + http_2xx: prober: http timeout: 5s http: valid_status_codes: [] # Defaults to 2xx + method: GET no_follow_redirects: false fail_if_ssl: false fail_if_not_ssl: false - tcpconnect: + tcp_connect: prober: tcp timeout: 5s icmp: diff --git a/blackbox.yml b/blackbox.yml index 3b4a850..09d1323 100644 --- a/blackbox.yml +++ b/blackbox.yml @@ -1,9 +1,14 @@ modules: - http2xx: + http_2xx: prober: http timeout: 5s http: - tcpconnect: + http_post_2xx: + prober: http + timeout: 5s + http: + method: POST + tcp_connect: prober: tcp timeout: 5s icmp: diff --git a/http.go b/http.go index ccf2394..8e14758 100644 --- a/http.go +++ b/http.go @@ -5,7 +5,10 @@ import ( "errors" "fmt" "net/http" + "strings" "time" + + "github.com/prometheus/log" ) func getEarliestCertExpiry(state *tls.ConnectionState) time.Time { @@ -35,8 +38,19 @@ func probeHTTP(target string, w http.ResponseWriter, module Module) (success boo } } - resp, err := client.Get(target) - if err == nil { + if !strings.HasPrefix(target, "http://") && !strings.HasPrefix(target, "https://") { + target = "http://" + target + } + + request, err := http.NewRequest(config.Method, target, nil) + if err != nil { + log.Errorf("Error creating request for target %s: %s", target, err) + } + + resp, err := client.Do(request) + if err != nil { + log.Warnf("Error for HTTP request to %s: %s", target, err) + } else { defer resp.Body.Close() if len(config.ValidStatusCodes) != 0 { for _, code := range config.ValidStatusCodes { diff --git a/icmp.go b/icmp.go index fb46f66..103d894 100644 --- a/icmp.go +++ b/icmp.go @@ -3,7 +3,6 @@ package main import ( "bytes" "golang.org/x/net/icmp" - "golang.org/x/net/internal/iana" "golang.org/x/net/ipv4" "net" "net/http" diff --git a/main.go b/main.go index d3889ab..5e8df76 100644 --- a/main.go +++ b/main.go @@ -29,10 +29,11 @@ type Module struct { type HTTPProbe struct { // Defaults to 2xx. - ValidStatusCodes []int `yaml:"valid_status_codes"` - NoFollowRedirects bool `yaml:"no_follow_redirects"` - FailIfSSL bool `yaml:"fail_if_ssl"` - FailIfNotSSL bool `yaml:"fail_if_not_ssl"` + ValidStatusCodes []int `yaml:"valid_status_codes"` + NoFollowRedirects bool `yaml:"no_follow_redirects"` + FailIfSSL bool `yaml:"fail_if_ssl"` + FailIfNotSSL bool `yaml:"fail_if_not_ssl"` + Method string `yaml:"method"` } type TCPProbe struct { @@ -104,7 +105,7 @@ func main() { Blackbox Exporter

Blackbox Exporter

-

Probe prometheus.io for http2xx

+

Probe prometheus.io for http_2xx

Metrics

`))