Skip to content

Addition of username/password into the prometheus modular input stanza #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ sourcetype = prometheus:metric
host = myhost
interval = 60
disabled = 0
username = <optional username>
password = <optional 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.
Expand All @@ -150,6 +152,8 @@ sourcetype = prometheus:metric
host = myhost
interval = 60
disabled = 0
username = <optional username>
password = <optional password>
```

### Prometheus remote-write
Expand Down
6 changes: 6 additions & 0 deletions modinput_prometheus/README/inputs.conf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ match = <match expression>,<match expression>,...

insecureSkipVerify = <0|1>
* If the URI is HTTPS, this controls whether the server certificate must be verified in order to continue

username = <string>
* Provide an optional username to be used with the Prometheus federate endpoint

password = <string>
* Provide an optional password to be used with the Prometheus federate endpoint
25 changes: 25 additions & 0 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type inputConfig struct {
Index string
Sourcetype string
Host string
Username string
Password string
}

var (
Expand Down Expand Up @@ -173,6 +175,18 @@ func doScheme() string {
<required_on_edit>false</required_on_edit>
<required_on_create>false</required_on_create>
</arg>
<arg name="username">
<title>Username</title>
<description>If supplied uses a username in basic auth requests to the endpoint</description>
<required_on_edit>false</required_on_edit>
<required_on_create>false</required_on_create>
</arg>
<arg name="password">
<title>Password</title>
<description>If supplied uses a password in basic auth requests to the endpoint</description>
<required_on_edit>false</required_on_edit>
<required_on_create>false</required_on_create>
</arg>
</endpoint>
</scheme>`

Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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)

Expand Down