diff --git a/plugins/inputs/example/example.go b/plugins/inputs/example/example.go index 59f49e56a..5adea27a0 100644 --- a/plugins/inputs/example/example.go +++ b/plugins/inputs/example/example.go @@ -29,6 +29,10 @@ type Example struct { // Example of passing a duration option allowing the format of e.g. "100ms", "5m" or "1h" Timeout config.Duration `toml:"timeout"` + // Example of passing a password/token/username or other sensitive data with the secret-store + UserName config.Secret `toml:"username"` + Password config.Secret `toml:"password"` + // Telegraf logging facility // The exact name is important to allow automatic initialization by telegraf. Log telegraf.Logger `toml:"-"` @@ -56,6 +60,19 @@ func (m *Example) Init() error { m.NumberFields = 2 } + // Check using the secret-store + if m.UserName.Empty() { + // For example, use a default value + m.Log.Debug("using default username") + } + + // Retrieve credentials using the secret-store + password, err := m.Password.Get() + if err != nil { + return fmt.Errorf("getting password failed: %w", err) + } + defer config.ReleaseSecret(password) + // Initialze your internal states m.count = 1