Skip to content

Commit

Permalink
Add option to fail on parse errors in the generator.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
SuperQ committed Feb 15, 2019
1 parent 1e05bcb commit 3332801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions generator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ clean:
$(MIBDIR)/.paloalto_panos \
$(MIBDIR)/.synology

generator:
generator: *.go
go build

generate: generator mibs
MIBDIRS=$(MIB_PATH) ./generator generate
MIBDIRS=$(MIB_PATH) ./generator --fail-on-parse-errors generate

parse_errors: generator mibs
MIBDIRS=$(MIB_PATH) ./generator parse_errors
MIBDIRS=$(MIB_PATH) ./generator --fail-on-parse-errors parse_errors

.PHONY: mibs
mibs: mib-dir \
Expand Down
9 changes: 8 additions & 1 deletion generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func generateConfig(nodes *Node, nameToNode map[string]*Node) {
}

var (
failOnParseErrors = kingpin.Flag("fail-on-parse-errors", "Exit with a non-zero status if there are parse errors").Default("false").Bool()
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 All @@ -98,10 +99,15 @@ func main() {
command := kingpin.Parse()

parseErrors := initSNMP()
parseErrorCount := len(parseErrors)

if len(parseErrors) != 0 {
if !*failOnParseErrors {
parseErrorCount = 0
}
if parseErrorCount != 0 {
log.Warnf("NetSNMP reported %d parse errors", len(strings.Split(parseErrors, "\n")))
}

nodes := getMIBTree()
nameToNode := prepareTree(nodes)

Expand All @@ -124,4 +130,5 @@ func main() {
n.Oid, n.Label, t, n.TextualConvention, n.Hint, n.Indexes, implied, n.EnumValues, n.Description)
})
}
os.Exit(parseErrorCount)
}

0 comments on commit 3332801

Please sign in to comment.