From c416cf97cb3aa140934175d98afc8399a50291e5 Mon Sep 17 00:00:00 2001 From: gjanders Date: Tue, 26 Nov 2019 19:47:45 +1100 Subject: [PATCH 1/2] Add files via upload --- Makefile | 6 ----- README.md | 4 ++++ modinput_prometheus/README/inputs.conf.spec | 6 +++++ prometheus/prometheus.go | 25 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index cf40586..d4f2925 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,6 @@ build: - make -B prometheusrw make -B prometheus -prometheusrw: prometheusrw/prometheusrw.go - go build -o ./out/prometheusrw ./prometheusrw/prometheusrw.go - - mv ./out/prometheusrw modinput_prometheus/linux_x86_64/bin/ - prometheus: prometheus/prometheus.go go build -o ./out/prometheus ./prometheus/prometheus.go mv ./out/prometheus modinput_prometheus/linux_x86_64/bin/ 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) From ef4da9d365c9c46078754bd6c2d04c6bd80e55b9 Mon Sep 17 00:00:00 2001 From: gjanders Date: Tue, 26 Nov 2019 19:49:44 +1100 Subject: [PATCH 2/2] Add files via upload --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index d4f2925..cf40586 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,12 @@ build: + make -B prometheusrw make -B prometheus +prometheusrw: prometheusrw/prometheusrw.go + go build -o ./out/prometheusrw ./prometheusrw/prometheusrw.go + + mv ./out/prometheusrw modinput_prometheus/linux_x86_64/bin/ + prometheus: prometheus/prometheus.go go build -o ./out/prometheus ./prometheus/prometheus.go mv ./out/prometheus modinput_prometheus/linux_x86_64/bin/