Prevent new tag from being overwritten

Resolves #4374
This commit is contained in:
Greg Linton 2018-07-05 10:23:58 -06:00
parent bf076dab73
commit 2e724d8d02
1 changed files with 9 additions and 3 deletions

View File

@ -67,7 +67,10 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric {
for _, metric := range in { for _, metric := range in {
for _, converter := range r.Tags { for _, converter := range r.Tags {
if value, ok := metric.GetTag(converter.Key); ok { if value, ok := metric.GetTag(converter.Key); ok {
metric.AddTag(r.convert(converter, value)) k, v := r.convert(converter, value)
if k != "" && v != "" {
metric.AddTag(k, v)
}
} }
} }
@ -75,7 +78,10 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric {
if value, ok := metric.GetField(converter.Key); ok { if value, ok := metric.GetField(converter.Key); ok {
switch value := value.(type) { switch value := value.(type) {
case string: case string:
metric.AddField(r.convert(converter, value)) k, v := r.convert(converter, value)
if k != "" && v != "" {
metric.AddField(r.convert(converter, value))
}
} }
} }
} }