Skip to content

Commit

Permalink
generator: add a --config-file= option
Browse files Browse the repository at this point in the history
This allows easier use of multiple generator config files, for example
for different sets of authentication credentials or to break up the
giant snmp.yml file into smaller chunks that fit better in a Kubernetes
ConfigMap.
  • Loading branch information
bootc committed Apr 4, 2021
1 parent b84255d commit 2da4947
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func generateConfig(nodes *Node, nameToNode map[string]*Node, logger log.Logger)
return fmt.Errorf("unable to determine absolute path for output")
}

content, err := ioutil.ReadFile("generator.yml")
configPath, err := filepath.Abs(*configPath)
if err != nil {
return fmt.Errorf("unable to determine absolute path for configuration file")
}

content, err := ioutil.ReadFile(configPath)
if err != nil {
return fmt.Errorf("error reading yml config: %s", err)
}
Expand Down Expand Up @@ -95,6 +100,7 @@ func generateConfig(nodes *Node, nameToNode map[string]*Node, logger log.Logger)

var (
failOnParseErrors = kingpin.Flag("fail-on-parse-errors", "Exit with a non-zero status if there are MIB parsing errors").Default("false").Bool()
configPath = kingpin.Flag("config-file", "Path to configuration file").Default("generator.yml").Short('c').String()
generateCommand = kingpin.Command("generate", "Generate snmp.yml from generator.yml")
outputPath = generateCommand.Flag("output-path", "Path to to write resulting config file").Default("snmp.yml").Short('o').String()
parseErrorsCommand = kingpin.Command("parse_errors", "Debug: Print the parse errors output by NetSNMP")
Expand Down

0 comments on commit 2da4947

Please sign in to comment.