Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ The other placeholders are specified separately.
[ preferred_ip_protocol: <string> | default = "ip6" ]
[ ip_protocol_fallback: <boolean> | default = true ]

# The source IP address.
[ source_ip_address: <string> ]

# The body of the HTTP request used in probe.
body: [ <string> ]

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ type HTTPProbe struct {
ValidHTTPVersions []string `yaml:"valid_http_versions,omitempty"`
IPProtocol string `yaml:"preferred_ip_protocol,omitempty"`
IPProtocolFallback bool `yaml:"ip_protocol_fallback,omitempty"`
SourceIPAddress string `yaml:"source_ip_address,omitempty"`
NoFollowRedirects bool `yaml:"no_follow_redirects,omitempty"`
FailIfSSL bool `yaml:"fail_if_ssl,omitempty"`
FailIfNotSSL bool `yaml:"fail_if_not_ssl,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/prometheus/blackbox_exporter
require (
github.com/go-kit/kit v0.10.0
github.com/miekg/dns v1.1.40
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/client_model v0.2.0
Expand Down
26 changes: 26 additions & 0 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/mwitkow/go-conntrack"
"github.com/prometheus/client_golang/prometheus"
pconfig "github.com/prometheus/common/config"
"golang.org/x/net/publicsuffix"
Expand Down Expand Up @@ -329,6 +330,7 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
// the hostname of the target.
httpClientConfig.TLSConfig.ServerName = targetHost
}

client, err := pconfig.NewClientFromConfig(httpClientConfig, "http_probe", true, true)
if err != nil {
level.Error(logger).Log("msg", "Error generating HTTP client", "err", err)
Expand All @@ -352,6 +354,30 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
// Inject transport that tracks traces for each redirect,
// and does not set TLS ServerNames on redirect if needed.
tt := newTransport(client.Transport, noServerName, logger)

var localAddr net.Addr
if len(module.HTTP.SourceIPAddress) > 0 {
srcIP := net.ParseIP(module.HTTP.SourceIPAddress)
if srcIP == nil {
level.Error(logger).Log("msg", "Error parsing source ip address", "srcIP", module.HTTP.SourceIPAddress)
return false
}
level.Info(logger).Log("msg", "Using local address", "srcIP", srcIP)

localAddr = &net.TCPAddr{IP: srcIP}
}

dialContext := conntrack.NewDialContextFunc(
conntrack.DialWithTracing(),
conntrack.DialWithName("http_probe"),
conntrack.DialWithDialContextFunc(func(ctx context.Context, network string, address string) (net.Conn, error) {
return (&net.Dialer{LocalAddr: localAddr}).DialContext(ctx, network, address)
}),
)

tt.Transport.(*http.Transport).DialContext = dialContext
tt.NoServerNameTransport.(*http.Transport).DialContext = dialContext

client.Transport = tt

client.CheckRedirect = func(r *http.Request, via []*http.Request) error {
Expand Down