Added "name" parameter to NATS output plugin (#8429)

This commit is contained in:
Olli-Pekka Lehto 2020-11-27 10:24:26 -06:00 committed by GitHub
parent 4090c77275
commit f5d5a51c21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -6,6 +6,10 @@ This plugin writes to a (list of) specified NATS instance(s).
[[outputs.nats]] [[outputs.nats]]
## URLs of NATS servers ## URLs of NATS servers
servers = ["nats://localhost:4222"] servers = ["nats://localhost:4222"]
## Optional client name
# name = ""
## Optional credentials ## Optional credentials
# username = "" # username = ""
# password = "" # password = ""

View File

@ -15,6 +15,7 @@ import (
type NATS struct { type NATS struct {
Servers []string `toml:"servers"` Servers []string `toml:"servers"`
Secure bool `toml:"secure"` Secure bool `toml:"secure"`
Name string `toml:"name"`
Username string `toml:"username"` Username string `toml:"username"`
Password string `toml:"password"` Password string `toml:"password"`
Credentials string `toml:"credentials"` Credentials string `toml:"credentials"`
@ -30,6 +31,9 @@ var sampleConfig = `
## URLs of NATS servers ## URLs of NATS servers
servers = ["nats://localhost:4222"] servers = ["nats://localhost:4222"]
## Optional client name
# name = ""
## Optional credentials ## Optional credentials
# username = "" # username = ""
# password = "" # password = ""
@ -73,6 +77,10 @@ func (n *NATS) Connect() error {
opts = append(opts, nats.UserInfo(n.Username, n.Password)) opts = append(opts, nats.UserInfo(n.Username, n.Password))
} }
if n.Name != "" {
opts = append(opts, nats.Name(n.Name))
}
if n.Secure { if n.Secure {
tlsConfig, err := n.ClientConfig.TLSConfig() tlsConfig, err := n.ClientConfig.TLSConfig()
if err != nil { if err != nil {

View File

@ -17,6 +17,7 @@ func TestConnectAndWrite(t *testing.T) {
s, _ := serializers.NewInfluxSerializer() s, _ := serializers.NewInfluxSerializer()
n := &NATS{ n := &NATS{
Servers: server, Servers: server,
Name: "telegraf",
Subject: "telegraf", Subject: "telegraf",
serializer: s, serializer: s,
} }