Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getting datasource names from types.db #35

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
collectdAddress = flag.String("collectd.listen-address", "", "Network address on which to accept collectd binary network packets, e.g. \":25826\".")
collectdAuth = flag.String("collectd.auth-file", "", "File mapping user names to pre-shared keys (passwords).")
collectdSecurity = flag.String("collectd.security-level", "None", "Minimum required security level for accepted packets. Must be one of \"None\", \"Sign\" and \"Encrypt\".")
collectdTypesDB = flag.String("collectd.typesdb-file", "", "Collectd types.db file for datasource names mapping. Needed only if using a binary network protocol.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose Prometheus metrics.")
collectdPostPath = flag.String("web.collectd-push-path", "/collectd-post", "Path under which to accept POST requests from collectd.")
lastPush = prometheus.NewGauge(
Expand Down Expand Up @@ -237,6 +238,20 @@ func startCollectdServer(ctx context.Context, w api.Writer) {
srv.PasswordLookup = network.NewAuthFile(*collectdAuth)
}

if *collectdTypesDB != "" {
file, err := os.Open(*collectdTypesDB)
if err != nil {
log.Fatalf("Can't open types.db file %s", *collectdTypesDB)
}
defer file.Close()

typesDB, err := api.NewTypesDB(file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close file after parsing it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, indeed, fixed.

if err != nil {
log.Fatalf("Error in parsing types.db file %s", *collectdTypesDB)
}
srv.TypesDB = typesDB
}

switch strings.ToLower(*collectdSecurity) {
case "", "none":
srv.SecurityLevel = network.None
Expand Down