gotelegraftelegraf-inputs-plugin

Can't get config toml file to load information to telegraf input plugin


I've created an input plugin that has two parameters that are taken from the configuration file, as specified in the struct. For some unknown reason, the plugin refuses to run:

The struct:

type Plugin struct {
    Address       string `toml:"address"`
    lines_to_read string `toml:"lines_to_read"`
}

This is the input plugin section of the configuration toml file plugin.conf:

[[inputs.plugin]]
  address = "the/filepath.txt"
  lines_to_read = "20"

I run a make on the file every time I change the go file and then run this command:

./telegraf -config plugin.conf -test

and I get this error:

E! error loading config file plugin.conf: plugin inputs.plugin: line 1156: configuration specified the fields ["lines_to_read"], but they weren't used

It has no problems loading the address, but the "lines_to_read" value constantly throws this error. Do you have any idea what's going on?

Tried removing "lines_to_read", ran fine. Tried removing underscores. No change. Tried running make again and checking for errors. Make runs fine.


Solution

  • telegraf uses the package github.com/influxdata/toml to unmarshal toml data. The package requires that The fields of struct for mapping must be exported (See https://pkg.go.dev/github.com/influxdata/toml#section-readme).

    Try to export the field by renaming it from lines_to_read to LinesToRead:

     type Plugin struct {
         Address       string `toml:"address"`
    -    lines_to_read string `toml:"lines_to_read"`
    +    LinesToRead   string `toml:"lines_to_read"`
    }