From a49e8c3da878e75c785679d81a140e4f55cc8f2e Mon Sep 17 00:00:00 2001 From: theS1LV3R Date: Thu, 11 Jan 2024 00:20:18 +0100 Subject: [PATCH] Add User-Agent header (#185) Set to format: Prometheus-Apache-Exporter/%s --- collector/collector.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/collector/collector.go b/collector/collector.go index 244ce06..715d9d5 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -10,6 +10,7 @@ package collector import ( "crypto/tls" "fmt" + "github.com/prometheus/common/version" "io" "net/http" "strconv" @@ -31,6 +32,7 @@ type Exporter struct { customHeaders map[string]string mutex sync.Mutex client *http.Client + userAgent string up *prometheus.Desc scrapeFailures prometheus.Counter @@ -197,6 +199,7 @@ func NewExporter(logger log.Logger, config *Config) *Exporter { TLSClientConfig: &tls.Config{InsecureSkipVerify: config.Insecure}, }, }, + userAgent: fmt.Sprintf("Prometheus-Apache-Exporter/%s", version.Version), } } @@ -273,6 +276,7 @@ func (e *Exporter) updateScoreboard(scoreboard string) { func (e *Exporter) collect(ch chan<- prometheus.Metric) error { req, err := http.NewRequest("GET", e.URI, nil) + req.Header.Set("User-Agent", e.userAgent) if e.hostOverride != "" { req.Host = e.hostOverride }