-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathsyslog.go
74 lines (61 loc) · 2.55 KB
/
syslog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package syslogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver"
import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/receiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/consumerretry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/syslog"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/tcp"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/udp"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver/internal/metadata"
)
// NewFactory creates a factory for syslog receiver
func NewFactory() receiver.Factory {
return adapter.NewFactory(ReceiverType{}, metadata.LogsStability)
}
// ReceiverType implements adapter.LogReceiverType
// to create a syslog receiver
type ReceiverType struct{}
// Type is the receiver type
func (f ReceiverType) Type() component.Type {
return metadata.Type
}
// CreateDefaultConfig creates a config with type and version
func (f ReceiverType) CreateDefaultConfig() component.Config {
return &SysLogConfig{
BaseConfig: adapter.BaseConfig{
Operators: []operator.Config{},
RetryOnFailure: consumerretry.NewDefaultConfig(),
},
InputConfig: *syslog.NewConfig(),
}
}
// BaseConfig gets the base config from config, for now
func (f ReceiverType) BaseConfig(cfg component.Config) adapter.BaseConfig {
return cfg.(*SysLogConfig).BaseConfig
}
// SysLogConfig defines configuration for the syslog receiver
type SysLogConfig struct {
InputConfig syslog.Config `mapstructure:",squash"`
adapter.BaseConfig `mapstructure:",squash"`
}
// InputConfig unmarshals the input operator
func (f ReceiverType) InputConfig(cfg component.Config) operator.Config {
return operator.NewConfig(&cfg.(*SysLogConfig).InputConfig)
}
func (cfg *SysLogConfig) Unmarshal(componentParser *confmap.Conf) error {
if componentParser == nil {
// Nothing to do if there is no config given.
return nil
}
if componentParser.IsSet("tcp") {
cfg.InputConfig.TCP = &tcp.NewConfig().BaseConfig
} else if componentParser.IsSet("udp") {
cfg.InputConfig.UDP = &udp.NewConfig().BaseConfig
}
return componentParser.Unmarshal(cfg)
}