diff --git a/generator/config.go b/generator/config.go index 1833126d..dcf81493 100644 --- a/generator/config.go +++ b/generator/config.go @@ -15,8 +15,8 @@ package main import ( "fmt" - "github.com/prometheus/snmp_exporter/config" + "strconv" ) // The generator config. @@ -53,6 +53,26 @@ type ModuleConfig struct { Filters config.Filters `yaml:"filters,omitempty"` } +// UnmarshalYAML implements the yaml.Unmarshaler interface. +func (c *ModuleConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + type plain ModuleConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + + // Ensure indices in static filters are integer for input validation. + for _, filter := range c.Filters.Static { + for _, index := range filter.Indices { + _, err := strconv.Atoi(index) + if err != nil { + return fmt.Errorf("invalid index '%s'. Index must be integer", index) + } + } + } + + return nil +} + type Lookup struct { SourceIndexes []string `yaml:"source_indexes"` Lookup string `yaml:"lookup"`