Fix a segmentation fault that would occur when a https URL redirected to http. I've also added a block to catch cases where the response is unencrypted and removed the checks against the tagret parameter. If the target is invalid it will be caught when we make the request.

This commit is contained in:
Rob Best
2017-10-08 18:01:03 +01:00
parent 57063a77df
commit e036e6415a

View File

@@ -80,6 +80,9 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
TLSClientConfig: &tls.Config{InsecureSkipVerify: e.insecure},
}
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Transport: tr,
Timeout: e.timeout,
}
@@ -92,6 +95,15 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
)
return
}
if resp.TLS == nil {
log.Errorln("The response from " + e.target + " is unencrypted")
ch <- prometheus.MustNewConstMetric(
httpsConnectSuccess, prometheus.GaugeValue, 0,
)
return
}
ch <- prometheus.MustNewConstMetric(
httpsConnectSuccess, prometheus.GaugeValue, 1,
)
@@ -152,16 +164,6 @@ func probeHandler(w http.ResponseWriter, r *http.Request, insecure bool) {
target := r.URL.Query().Get("target")
if target == "" {
http.Error(w, "Target parameter is missing", 400)
return
}
if strings.HasPrefix(target, "http://") {
http.Error(w, "Target is using the http:// protocol", 400)
return
}
// The following timeout block was taken wholly from the blackbox exporter
// https://github.com/prometheus/blackbox_exporter/blob/master/main.go
var timeoutSeconds float64