2018-10-05 21:43:01 +00:00
|
|
|
package inputs
|
|
|
|
|
|
|
|
import (
|
2018-10-17 19:51:35 +00:00
|
|
|
"errors"
|
2018-10-05 21:43:01 +00:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Syslog is based on telegraf Syslog plugin.
|
|
|
|
type Syslog struct {
|
2018-10-16 00:38:36 +00:00
|
|
|
baseInput
|
2018-10-05 21:43:01 +00:00
|
|
|
Address string `json:"server"`
|
|
|
|
}
|
|
|
|
|
2018-10-16 00:38:36 +00:00
|
|
|
// PluginName is based on telegraf plugin name.
|
|
|
|
func (s *Syslog) PluginName() string {
|
|
|
|
return "syslog"
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:43:01 +00:00
|
|
|
// TOML encodes to toml string
|
|
|
|
func (s *Syslog) TOML() string {
|
2018-10-16 00:38:36 +00:00
|
|
|
return fmt.Sprintf(`[[inputs.%s]]
|
2018-10-05 21:43:01 +00:00
|
|
|
## Specify an ip or hostname with port - eg., tcp://localhost:6514, tcp://10.0.0.1:6514
|
|
|
|
## Protocol, address and port to host the syslog receiver.
|
|
|
|
## If no host is specified, then localhost is used.
|
|
|
|
## If no port is specified, 6514 is used (RFC5425#section-4.1).
|
2018-10-05 21:43:01 +00:00
|
|
|
server = "%s"
|
2018-10-16 00:38:36 +00:00
|
|
|
`, s.PluginName(), s.Address)
|
2018-10-05 21:43:01 +00:00
|
|
|
}
|
2018-10-17 19:51:35 +00:00
|
|
|
|
|
|
|
// UnmarshalTOML decodes the parsed data to the object
|
|
|
|
func (s *Syslog) UnmarshalTOML(data interface{}) error {
|
|
|
|
dataOK, ok := data.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return errors.New("bad server for syslog input plugin")
|
|
|
|
}
|
|
|
|
s.Address, _ = dataOK["server"].(string)
|
|
|
|
return nil
|
|
|
|
}
|