Make http method configurable
authorBrian Brazil <brian.brazil@robustperception.io>
Sun, 6 Sep 2015 06:57:59 +0000 (07:57 +0100)
committerBrian Brazil <brian.brazil@robustperception.io>
Sun, 6 Sep 2015 06:57:59 +0000 (07:57 +0100)
README.md
blackbox.yml
http.go
icmp.go
main.go

index f71628d317f763d961cfd7fceb5e1c72fb571c9c..ff5d75d8e36b3d43c4a111e04a4e0d9138c59cd8 100644 (file)
--- 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:
index 3b4a8508602c60433535d932f1223306711c8cda..09d132374cc44f9e1416c75713b0c1fade239484 100644 (file)
@@ -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 ccf2394e320c02d4152d385680141263e51026b1..8e1475868034ae7567b01eada2b6c9604272867d 100644 (file)
--- 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 fb46f66265beab1aa925979d95cb7231ad0b9d1d..103d894125a15b3d8c325417d31b203dc67c4af6 100644 (file)
--- 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 d3889ab78c05051a88572381821a694a60207ae8..5e8df76f95565aea6a13c33dda73225e2b36750c 100644 (file)
--- 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() {
             <head><title>Blackbox Exporter</title></head>
             <body>
             <h1>Blackbox Exporter</h1>
-            <p><a href="/probe?target=prometheus.io&module=http2xx">Probe prometheus.io for http2xx</a></p>
+            <p><a href="/probe?target=prometheus.io&module=http2xx">Probe prometheus.io for http_2xx</a></p>
             <p><a href="/metrics">Metrics</a></p>
             </body>
             </html>`))