10
"go.avito.ru/DO/moira"
11
"go.avito.ru/DO/moira/database/redis"
12
"go.avito.ru/DO/moira/logging"
13
"go.avito.ru/DO/moira/metrics"
14
"go.avito.ru/DO/moira/netbox"
15
"go.avito.ru/DO/moira/sentry"
18
// RedisConfig is redis config structure, which are taken on the start of moira
19
type RedisConfig struct {
20
Host string `yaml:"host"`
21
Port string `yaml:"port"`
22
DBID int `yaml:"dbid"`
25
// GetSettings return redis config parsed from moira config files
26
func (config *RedisConfig) GetSettings() redis.Config {
34
type Neo4jConfig struct {
35
Host string `yaml:"host"`
36
Port int `yaml:"port"`
37
DBName string `yaml:"db_name"`
38
User string `yaml:"user"`
39
Password string `yaml:"password"`
40
PasswordPath string `yaml:"password_path"`
43
// LoggerConfig is logger settings, which are taken on the start of moira
44
type LoggerConfig struct {
45
LogFile string `yaml:"log_file"`
46
LogLevel string `yaml:"log_level"`
49
// NetboxConfig is settings of netbox client, which are taken on the start of moira
50
type NetboxConfig struct {
51
Enabled bool `yaml:"enabled"`
52
Token string `yaml:"token"`
53
URL string `yaml:"url"`
56
func (netboxConfig *NetboxConfig) GetSettings() *netbox.Config {
57
if !netboxConfig.Enabled {
61
token, _ := moira.GetFileContent(netboxConfig.Token)
62
url := strings.TrimSuffix(netboxConfig.URL, "/")
63
return &netbox.Config{
64
Token: strings.TrimSpace(token),
69
type RateLimit struct {
70
AcceptRate float64 `yaml:"rate"`
71
ThreadsQty int `yaml:"threads"`
74
func NewDefaultLoggerRateLimit() RateLimit {
81
func NewDefaultMetricsRateLimit() RateLimit {
88
func (rateLimit *RateLimit) GetSettings() moira.RateLimit {
90
acceptRate = rateLimit.AcceptRate
91
threadsQty = rateLimit.ThreadsQty
102
return moira.RateLimit{
103
AcceptRate: acceptRate,
104
ThreadsQty: threadsQty,
108
type RsyslogConfig struct {
109
Enabled bool `yaml:"enabled"`
110
Host string `yaml:"host"`
111
Port int `yaml:"port"`
112
Level string `yaml:"level"`
113
Fallback string `yaml:"fallback"`
114
Debug bool `yaml:"debug"`
117
func (rsyslogConfig *RsyslogConfig) GetSettings() logging.Config {
118
return logging.Config{
119
Enabled: rsyslogConfig.Enabled,
120
Host: rsyslogConfig.Host,
121
Port: rsyslogConfig.Port,
122
Level: rsyslogConfig.Level,
123
Fallback: rsyslogConfig.Fallback,
124
Debug: rsyslogConfig.Debug,
128
type StatsdConfig struct {
129
Enabled bool `yaml:"enabled"`
130
Host string `yaml:"host"`
131
Port int `yaml:"port"`
132
Prefix string `yaml:"prefix"`
135
func (statsdConfig *StatsdConfig) GetSettings() metrics.Config {
136
return metrics.Config{
137
Enabled: statsdConfig.Enabled,
138
Host: statsdConfig.Host,
139
Port: statsdConfig.Port,
140
Prefix: statsdConfig.Prefix,
144
// ProfilerConfig is pprof settings, which are taken on the start of moira
145
type ProfilerConfig struct {
146
Listen string `yaml:"listen"`
149
// LivenessConfig is liveness check settings, which are taken on the start of moira
150
type LivenessConfig struct {
151
Listen string `yaml:"listen"`
154
// SentryConfig is configuration for sentry reporter
155
type SentryConfig struct {
156
Dsn string `yaml:"dsn"`
157
Enabled bool `yaml:"enabled"`
158
IsFilePath bool `yaml:"is_file_path"`
161
func (sentryConfig *SentryConfig) GetSettings() sentry.Config {
162
return sentry.Config{
163
Dsn: sentryConfig.Dsn,
164
Enabled: sentryConfig.Enabled,
165
IsFilePath: sentryConfig.IsFilePath,
169
// ReadConfig gets config file by given file and marshal it to moira-used type
170
func ReadConfig(configFileName string, config interface{}) error {
171
configYaml, err := ioutil.ReadFile(configFileName)
173
return fmt.Errorf("Can't read file [%s] [%s]", configFileName, err.Error())
175
err = yaml.Unmarshal(configYaml, config)
177
return fmt.Errorf("Can't parse config file [%s] [%s]", configFileName, err.Error())
182
// PrintConfig prints config to std
183
func PrintConfig(config interface{}) {
184
d, _ := yaml.Marshal(&config)
185
fmt.Println(string(d))