Skip to content

Commit

Permalink
Add optional auth credentials to Jolokia plugin
Browse files Browse the repository at this point in the history
closes #414
  • Loading branch information
sparrc committed Dec 3, 2015
1 parent 6fb7d28 commit 7a2eeb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features
- [#412](https://github.com/influxdb/telegraf/pull/412): Additional memcached stats. Thanks @mgresser!
- [#410](https://github.com/influxdb/telegraf/pull/410): Additional redis metrics. Thanks @vlaadbrain!
- [#414](https://github.com/influxdb/telegraf/issues/414): Jolokia plugin auth parameters

### Bugfixes
- [#405](https://github.com/influxdb/telegraf/issues/405): Prometheus output cardinality issue
Expand Down
16 changes: 12 additions & 4 deletions plugins/jolokia/jolokia.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
)

type Server struct {
Name string
Host string
Port string
Name string
Host string
Username string
Password string
Port string
}

type Metric struct {
Expand Down Expand Up @@ -59,6 +61,8 @@ func (j *Jolokia) SampleConfig() string {
name = "stable"
host = "192.168.103.2"
port = "8180"
# username = "myuser"
# password = "mypassword"
# List of metrics collected on above servers
# Each metric consists in a name, a jmx path and either a pass or drop slice attributes
Expand Down Expand Up @@ -193,10 +197,14 @@ func (j *Jolokia) Gather(acc plugins.Accumulator) error {
tags["host"] = server.Host

// Prepare URL
requestUrl, err := url.Parse("http://" + server.Host + ":" + server.Port + context + jmxPath)
requestUrl, err := url.Parse("http://" + server.Host + ":" +
server.Port + context + jmxPath)
if err != nil {
return err
}
if server.Username != "" || server.Password != "" {
requestUrl.User = url.UserPassword(server.Username, server.Password)
}

out, _ := j.getAttr(requestUrl)

Expand Down

0 comments on commit 7a2eeb7

Please sign in to comment.