fix(inputs.gnmi): Add option to explicitly trim field-names (#13517)
This commit is contained in:
parent
eb7ada1677
commit
cec60dbfa9
|
|
@ -55,6 +55,9 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|||
## Enable to get the canonical path as field-name
|
||||
# canonical_field_names = false
|
||||
|
||||
## Remove leading slashes and dots in field-name
|
||||
# trim_field_names = false
|
||||
|
||||
## enable client-side TLS and define CA to authenticate the device
|
||||
# enable_tls = false
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ type GNMI struct {
|
|||
MaxMsgSize config.Size `toml:"max_msg_size"`
|
||||
Trace bool `toml:"dump_responses"`
|
||||
CanonicalFieldNames bool `toml:"canonical_field_names"`
|
||||
TrimFieldNames bool `toml:"trim_field_names"`
|
||||
EnableTLS bool `toml:"enable_tls" deprecated:"1.27.0;use 'tls_enable' instead"`
|
||||
Log telegraf.Logger `toml:"-"`
|
||||
internaltls.ClientConfig
|
||||
|
|
@ -222,6 +223,7 @@ func (c *GNMI) Start(acc telegraf.Accumulator) error {
|
|||
tagStore: newTagStore(c.TagSubscriptions),
|
||||
trace: c.Trace,
|
||||
canonicalFieldNames: c.CanonicalFieldNames,
|
||||
trimSlash: c.TrimFieldNames,
|
||||
log: c.Log,
|
||||
}
|
||||
for ctx.Err() == nil {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ type handler struct {
|
|||
tagStore *tagStore
|
||||
trace bool
|
||||
canonicalFieldNames bool
|
||||
trimSlash bool
|
||||
log telegraf.Logger
|
||||
}
|
||||
|
||||
|
|
@ -254,7 +255,9 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
|
|||
key = path.Base(key)
|
||||
}
|
||||
}
|
||||
key = strings.TrimLeft(key, "/.")
|
||||
if h.trimSlash {
|
||||
key = strings.TrimLeft(key, "/.")
|
||||
}
|
||||
if key == "" {
|
||||
h.log.Errorf("invalid empty path: %q", k)
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
## Enable to get the canonical path as field-name
|
||||
# canonical_field_names = false
|
||||
|
||||
## Remove leading slashes and dots in field-name
|
||||
# trim_field_names = false
|
||||
|
||||
## enable client-side TLS and define CA to authenticate the device
|
||||
# enable_tls = false
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
interfaces,name=eth42,path=openconfig-interfaces:/interfaces/interface,source=127.0.0.1 interfaces/interface/descr="eth42",interfaces/interface/config/id=42425u,interfaces/interface/state/in_pkts=5678u,interfaces/interface/state/out_pkts=5125u 1673608605875353770
|
||||
interfaces,name=eth42,path=openconfig-interfaces:/interfaces/interface,source=127.0.0.1 /interfaces/interface/descr="eth42",/interfaces/interface/config/id=42425u,/interfaces/interface/state/in_pkts=5678u,/interfaces/interface/state/out_pkts=5125u 1673608605875353770
|
||||
|
|
@ -0,0 +1 @@
|
|||
interfaces,name=eth42,path=openconfig-interfaces:/interfaces/interface,source=127.0.0.1 interfaces/interface/descr="eth42",interfaces/interface/config/id=42425u,interfaces/interface/state/in_pkts=5678u,interfaces/interface/state/out_pkts=5125u 1673608605875353770
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
[
|
||||
{
|
||||
"update": {
|
||||
"timestamp": "1673608605875353770",
|
||||
"prefix": {
|
||||
"origin": "openconfig-interfaces",
|
||||
"elem": [
|
||||
{
|
||||
"name": "interfaces"
|
||||
},
|
||||
{
|
||||
"name": "interface",
|
||||
"key":{"name":"eth42"}
|
||||
}
|
||||
],
|
||||
"target": "subscription"
|
||||
},
|
||||
"update": [
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "descr"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"stringVal": "eth42"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "config"
|
||||
},
|
||||
{
|
||||
"name": "id"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"uintVal": "42425"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "state"
|
||||
},
|
||||
{
|
||||
"name": "in-pkts"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"uintVal": "5678"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "state"
|
||||
},
|
||||
{
|
||||
"name": "out-pkts"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"uintVal": "5125"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
[[inputs.gnmi]]
|
||||
addresses = ["dummy"]
|
||||
name_override = "gnmi"
|
||||
redial = "10s"
|
||||
canonical_field_names = true
|
||||
trim_field_names = true
|
||||
[[inputs.gnmi.subscription]]
|
||||
name = "interfaces"
|
||||
origin = "openconfig-interfaces"
|
||||
path = "/interfaces/interface/descr"
|
||||
subscription_mode = "sample"
|
||||
sample_interval = "10s"
|
||||
[[inputs.gnmi.subscription]]
|
||||
name = "interfaces"
|
||||
origin = "openconfig-interfaces"
|
||||
path = "/interfaces/interface/config/id"
|
||||
subscription_mode = "sample"
|
||||
sample_interval = "10s"
|
||||
[[inputs.gnmi.subscription]]
|
||||
name = "interfaces"
|
||||
origin = "openconfig-interfaces"
|
||||
path = "/interfaces/interface/state"
|
||||
subscription_mode = "sample"
|
||||
sample_interval = "10s"
|
||||
|
|
@ -0,0 +1 @@
|
|||
interfaces,name=eth42,path=openconfig-interfaces:/interfaces/interface,source=127.0.0.1 descr="eth42",id=42425u,in_pkts=5678u,out_pkts=5125u 1673608605875353770
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
[
|
||||
{
|
||||
"update": {
|
||||
"timestamp": "1673608605875353770",
|
||||
"prefix": {
|
||||
"origin": "openconfig-interfaces",
|
||||
"elem": [
|
||||
{
|
||||
"name": "interfaces"
|
||||
},
|
||||
{
|
||||
"name": "interface",
|
||||
"key":{"name":"eth42"}
|
||||
}
|
||||
],
|
||||
"target": "subscription"
|
||||
},
|
||||
"update": [
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "descr"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"stringVal": "eth42"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "config"
|
||||
},
|
||||
{
|
||||
"name": "id"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"uintVal": "42425"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "state"
|
||||
},
|
||||
{
|
||||
"name": "in-pkts"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"uintVal": "5678"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": {
|
||||
"elem": [
|
||||
{
|
||||
"name": "state"
|
||||
},
|
||||
{
|
||||
"name": "out-pkts"
|
||||
}
|
||||
]
|
||||
},
|
||||
"val": {
|
||||
"uintVal": "5125"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
[[inputs.gnmi]]
|
||||
addresses = ["dummy"]
|
||||
name_override = "gnmi"
|
||||
redial = "10s"
|
||||
[[inputs.gnmi.subscription]]
|
||||
name = "interfaces"
|
||||
origin = "openconfig-interfaces"
|
||||
path = "/interfaces/interface/descr"
|
||||
subscription_mode = "sample"
|
||||
sample_interval = "10s"
|
||||
[[inputs.gnmi.subscription]]
|
||||
name = "interfaces"
|
||||
origin = "openconfig-interfaces"
|
||||
path = "/interfaces/interface/config/id"
|
||||
subscription_mode = "sample"
|
||||
sample_interval = "10s"
|
||||
[[inputs.gnmi.subscription]]
|
||||
name = "interfaces"
|
||||
origin = "openconfig-interfaces"
|
||||
path = "/interfaces/interface/state"
|
||||
subscription_mode = "sample"
|
||||
sample_interval = "10s"
|
||||
Loading…
Reference in New Issue