diff --git a/Makefile b/Makefile index d2dceb4..a344081 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .POSIX: MIFLORA_ADDR?=00:00:00:00:00:00 +MIFLORAD_VERSION?=master RUN_COMMAND=miflorad RUN_OPTIONS=$(MIFLORA_ADDR) @@ -34,7 +35,7 @@ remote-run: clean .PHONY: cmd/munin-miflora/miflorad cmd/munin-miflora/miflorad: - cd cmd/miflorad && CGO_ENABLED=0 go build && cd ../.. + cd cmd/miflorad && CGO_ENABLED=0 go build -ldflags "-X main.version=$(MIFLORAD_VERSION)" && cd ../.. .PHONY: cmd/munin-miflora/munin-miflora cmd/munin-miflora/munin-miflora: diff --git a/cmd/miflorad/main.go b/cmd/miflorad/main.go index fc2016d..826229a 100644 --- a/cmd/miflorad/main.go +++ b/cmd/miflorad/main.go @@ -19,6 +19,9 @@ import ( "github.com/pkg/errors" ) +// program version, will be populated on build +var version string + var ( scanTimeout = flag.Duration("scantimeout", 10*time.Second, "timeout after that a scan per peripheral will be aborted") interval = flag.Duration("interval", 25*time.Second, "metrics collection interval") @@ -49,6 +52,14 @@ func checkTooShortInterval() error { return nil } +func getVersion() string { + if version == "" { + return "dev" + } else { + return version + } +} + func readData(peripheral *peripheral, client ble.Client) error { // re-request meta data (for battery level) if last check more than 24 hours ago // Source: https://github.com/open-homeautomation/miflora/blob/ffd95c3e616df8843cc8bff99c9b60765b124092/miflora/miflora_poller.py#L92 @@ -181,6 +192,8 @@ func main() { os.Exit(1) } + fmt.Fprintf(os.Stderr, "miflorad version %s\n", getVersion()) + device, err := dev.NewDevice("default") if err != nil { fmt.Fprintf(os.Stderr, "Failed to open device, err: %s\n", err)