2018-12-18 18:54:38 +00:00
|
|
|
package syslog
|
|
|
|
|
|
|
|
import (
|
2019-11-27 01:31:36 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf"
|
2018-12-18 18:54:38 +00:00
|
|
|
"github.com/influxdata/telegraf/internal"
|
2019-05-08 18:21:51 +00:00
|
|
|
framing "github.com/influxdata/telegraf/internal/syslog"
|
2018-12-18 18:54:38 +00:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
pki = testutil.NewPKI("../../../testutil/pki")
|
|
|
|
)
|
|
|
|
|
|
|
|
type testCasePacket struct {
|
|
|
|
name string
|
|
|
|
data []byte
|
2019-11-27 01:31:36 +00:00
|
|
|
wantBestEffort telegraf.Metric
|
|
|
|
wantStrict telegraf.Metric
|
2018-12-18 18:54:38 +00:00
|
|
|
werr bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type testCaseStream struct {
|
|
|
|
name string
|
|
|
|
data []byte
|
2019-11-27 01:31:36 +00:00
|
|
|
wantBestEffort []telegraf.Metric
|
|
|
|
wantStrict []telegraf.Metric
|
2018-12-18 18:54:38 +00:00
|
|
|
werr int // how many errors we expect in the strict mode?
|
|
|
|
}
|
|
|
|
|
|
|
|
func newUDPSyslogReceiver(address string, bestEffort bool) *Syslog {
|
|
|
|
return &Syslog{
|
|
|
|
Address: address,
|
|
|
|
now: func() time.Time {
|
|
|
|
return defaultTime
|
|
|
|
},
|
|
|
|
BestEffort: bestEffort,
|
|
|
|
Separator: "_",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 18:21:51 +00:00
|
|
|
func newTCPSyslogReceiver(address string, keepAlive *internal.Duration, maxConn int, bestEffort bool, f framing.Framing) *Syslog {
|
2018-12-18 18:54:38 +00:00
|
|
|
d := &internal.Duration{
|
|
|
|
Duration: defaultReadTimeout,
|
|
|
|
}
|
|
|
|
s := &Syslog{
|
|
|
|
Address: address,
|
|
|
|
now: func() time.Time {
|
|
|
|
return defaultTime
|
|
|
|
},
|
|
|
|
Framing: f,
|
|
|
|
ReadTimeout: d,
|
|
|
|
BestEffort: bestEffort,
|
|
|
|
Separator: "_",
|
|
|
|
}
|
|
|
|
if keepAlive != nil {
|
|
|
|
s.KeepAlivePeriod = keepAlive
|
|
|
|
}
|
|
|
|
if maxConn > 0 {
|
|
|
|
s.MaxConnections = maxConn
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|