Skip to content

Commit

Permalink
Added "name" parameter to NATS output plugin (#8429)
Browse files Browse the repository at this point in the history
  • Loading branch information
oplehto authored Nov 27, 2020
1 parent 4090c77 commit f5d5a51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/outputs/nats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This plugin writes to a (list of) specified NATS instance(s).
[[outputs.nats]]
## URLs of NATS servers
servers = ["nats://localhost:4222"]

## Optional client name
# name = ""

## Optional credentials
# username = ""
# password = ""
Expand Down
8 changes: 8 additions & 0 deletions plugins/outputs/nats/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
type NATS struct {
Servers []string `toml:"servers"`
Secure bool `toml:"secure"`
Name string `toml:"name"`
Username string `toml:"username"`
Password string `toml:"password"`
Credentials string `toml:"credentials"`
Expand All @@ -30,6 +31,9 @@ var sampleConfig = `
## URLs of NATS servers
servers = ["nats://localhost:4222"]
## Optional client name
# name = ""
## Optional credentials
# username = ""
# password = ""
Expand Down Expand Up @@ -73,6 +77,10 @@ func (n *NATS) Connect() error {
opts = append(opts, nats.UserInfo(n.Username, n.Password))
}

if n.Name != "" {
opts = append(opts, nats.Name(n.Name))
}

if n.Secure {
tlsConfig, err := n.ClientConfig.TLSConfig()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions plugins/outputs/nats/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestConnectAndWrite(t *testing.T) {
s, _ := serializers.NewInfluxSerializer()
n := &NATS{
Servers: server,
Name: "telegraf",
Subject: "telegraf",
serializer: s,
}
Expand Down

0 comments on commit f5d5a51

Please sign in to comment.