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]]
## URLs of NATS servers
servers = ["nats://localhost:4222"]
## Optional client name
# name = ""
## Optional credentials
# username = ""
# password = ""

View File

@ -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"`
@ -30,6 +31,9 @@ var sampleConfig = `
## URLs of NATS servers
servers = ["nats://localhost:4222"]
## Optional client name
# name = ""
## Optional credentials
# username = ""
# password = ""
@ -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 {

View File

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