mirror of
https://github.com/ribbybibby/ssl_exporter.git
synced 2026-02-14 17:49:58 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user