diff --git a/README.md b/README.md index 821d656..f87302a 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ sourcetype = prometheus:metric host = myhost interval = 60 disabled = 0 +username = +password = ``` The index should be a "metrics" type index. The sourcetype should be prometheus:metric, which is configured in the app to recognize the data format and convert it to Splunk metrics. @@ -150,6 +152,8 @@ sourcetype = prometheus:metric host = myhost interval = 60 disabled = 0 +username = +password = ``` ### Prometheus remote-write diff --git a/modinput_prometheus/README/inputs.conf.spec b/modinput_prometheus/README/inputs.conf.spec index 1d61df1..b54e611 100644 --- a/modinput_prometheus/README/inputs.conf.spec +++ b/modinput_prometheus/README/inputs.conf.spec @@ -57,3 +57,9 @@ match = ,,... insecureSkipVerify = <0|1> * If the URI is HTTPS, this controls whether the server certificate must be verified in order to continue + +username = +* Provide an optional username to be used with the Prometheus federate endpoint + +password = +* Provide an optional password to be used with the Prometheus federate endpoint diff --git a/prometheus/prometheus.go b/prometheus/prometheus.go index 499b327..fe3ffad 100644 --- a/prometheus/prometheus.go +++ b/prometheus/prometheus.go @@ -55,6 +55,8 @@ type inputConfig struct { Index string Sourcetype string Host string + Username string + Password string } var ( @@ -173,6 +175,18 @@ func doScheme() string { false false + + Username + If supplied uses a username in basic auth requests to the endpoint + false + false + + + Password + If supplied uses a password in basic auth requests to the endpoint + false + false + ` @@ -215,6 +229,12 @@ func config() inputConfig { inputConfig.Match = append(inputConfig.Match, m) } } + if p.Name == "username" { + inputConfig.Username = p.Value + } + if p.Name == "password" { + inputConfig.Password = p.Value + } } } @@ -246,6 +266,11 @@ func run() { // Debug request req.URL logDebug.Print(req.URL) + if inputConfig.Password != "" { + req.SetBasicAuth(inputConfig.Username, inputConfig.Password) + logDebug.Print(inputConfig.Username) + } + // Current timestamp in millis, used if response has no timestamps now := time.Now().UnixNano() / int64(time.Millisecond)