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

[feat] add --version flag and output version information #120

Merged
merged 1 commit into from
Aug 28, 2024
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
32 changes: 32 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ import (
"net/http"
"os"

_ "embed"
"github.com/alecthomas/kingpin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
version string
commit string
date string
builtBy string

//go:embed VERSION
fallbackVersion string
)

func main() {
var (
ctx = context.Background()
app = kingpin.New("postfix_exporter", "Prometheus metrics exporter for postfix")
versionFlag = app.Flag("version", "Print version information").Bool()
listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9154").String()
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String()
Expand All @@ -24,6 +36,26 @@ func main() {
InitLogSourceFactories(app)
kingpin.MustParse(app.Parse(os.Args[1:]))

if version == "" {
version = fallbackVersion
}

if *versionFlag {
os.Stdout.WriteString(version)
os.Exit(0)
}
versionString := "postfix_exporter " + version
if commit != "" {
versionString += " (" + commit + ")"
}
if date != "" {
versionString += " built on " + date
}
if builtBy != "" {
versionString += " by: " + builtBy
}
log.Print(versionString)

logSrc, err := NewLogSourceFromFactories(ctx)
if err != nil {
log.Fatalf("Error opening log source: %s", err)
Expand Down
Loading