diff --git a/internal/config/config.go b/internal/config/config.go index 7936ac04..c6d06b30 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,7 +2,10 @@ package config import ( "github.com/icinga/icingadb/pkg/database" + "github.com/icinga/icingadb/pkg/icingadb/history" "github.com/icinga/icingadb/pkg/logging" + "github.com/pkg/errors" + "time" ) // Config defines Icinga DB config. @@ -10,7 +13,7 @@ type Config struct { Database database.Config `yaml:"database"` Redis Redis `yaml:"redis"` Logging logging.Config `yaml:"logging"` - Retention Retention `yaml:"retention"` + Retention RetentionConfig `yaml:"retention"` } // Validate checks constraints in the supplied configuration and returns an error if they are violated. @@ -38,3 +41,26 @@ type Flags struct { // Config is the path to the config file Config string `short:"c" long:"config" description:"path to config file" required:"true" default:"/etc/icingadb/config.yml"` } + +// RetentionConfig defines configuration for history retention. +type RetentionConfig struct { + HistoryDays uint64 `yaml:"history-days"` + SlaDays uint64 `yaml:"sla-days"` + Interval time.Duration `yaml:"interval" default:"1h"` + Count uint64 `yaml:"count" default:"5000"` + Options history.RetentionOptions `yaml:"options"` +} + +// Validate checks constraints in the supplied retention configuration and +// returns an error if they are violated. +func (r *RetentionConfig) Validate() error { + if r.Interval <= 0 { + return errors.New("retention interval must be positive") + } + + if r.Count == 0 { + return errors.New("count must be greater than zero") + } + + return r.Options.Validate() +} diff --git a/internal/config/history_retention.go b/internal/config/history_retention.go deleted file mode 100644 index d4373b70..00000000 --- a/internal/config/history_retention.go +++ /dev/null @@ -1,30 +0,0 @@ -package config - -import ( - "github.com/icinga/icingadb/pkg/icingadb/history" - "github.com/pkg/errors" - "time" -) - -// Retention defines configuration for history retention. -type Retention struct { - HistoryDays uint64 `yaml:"history-days"` - SlaDays uint64 `yaml:"sla-days"` - Interval time.Duration `yaml:"interval" default:"1h"` - Count uint64 `yaml:"count" default:"5000"` - Options history.RetentionOptions `yaml:"options"` -} - -// Validate checks constraints in the supplied retention configuration and -// returns an error if they are violated. -func (r *Retention) Validate() error { - if r.Interval <= 0 { - return errors.New("retention interval must be positive") - } - - if r.Count == 0 { - return errors.New("count must be greater than zero") - } - - return r.Options.Validate() -}