feat(outputs.mqtt): Add sprig for topic name generator for homie layout (#16491)
Co-authored-by: Pieter Slabbert <pieter.slabbert@ilovezoona.com>
This commit is contained in:
parent
1b6350ac9f
commit
df2926978a
|
|
@ -201,6 +201,7 @@ while `homie_node_id` will provide a template for the `node-id` part of the
|
||||||
topic. Both options can contain [Go templates][GoTemplates] similar to `topic`
|
topic. Both options can contain [Go templates][GoTemplates] similar to `topic`
|
||||||
with `{{ .PluginName }}` referencing the metric name and `{{ .Tag "key"}}`
|
with `{{ .PluginName }}` referencing the metric name and `{{ .Tag "key"}}`
|
||||||
referencing the tag with the name `key`.
|
referencing the tag with the name `key`.
|
||||||
|
[Sprig](http://masterminds.github.io/sprig/) helper functions are available.
|
||||||
|
|
||||||
For example writing the metrics
|
For example writing the metrics
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/Masterminds/sprig/v3"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
)
|
)
|
||||||
|
|
@ -102,7 +104,7 @@ type HomieGenerator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHomieGenerator(tmpl string) (*HomieGenerator, error) {
|
func NewHomieGenerator(tmpl string) (*HomieGenerator, error) {
|
||||||
tt, err := template.New("topic_name").Parse(tmpl)
|
tt, err := template.New("topic_name").Funcs(sprig.TxtFuncMap()).Parse(tmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue