Skip to content

Commit

Permalink
Refactor: move app bootstrap out
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed Apr 3, 2021
1 parent 1180cd1 commit a96a718
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 50 deletions.
60 changes: 60 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package app

import (
"github.com/urfave/cli"
)

// NewApp ...
func NewApp(name string, version string) *cli.App {

cli.VersionFlag = cli.BoolFlag{
Name: "version, V",
Usage: "Print the version information.",
}

app := cli.NewApp()
app.Name = name
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config.dns-resolver",
Value: "127.0.0.1:53",
Usage: "IP address[:port] of the resolver to use.",
},
cli.StringFlag{
Name: "config.rbls",
Value: "./rbls.ini",
Usage: "Configuration file which contains RBLs",
},
cli.StringFlag{
Name: "config.targets",
Value: "./targets.ini",
Usage: "Configuration file which contains the targets to check.",
},
cli.StringFlag{
Name: "web.listen-address",
Value: ":9211",
Usage: "Address to listen on for web interface and telemetry.",
},
cli.StringFlag{
Name: "web.telemetry-path",
Value: "/metrics",
Usage: "Path under which to expose metrics.",
},
cli.BoolFlag{
Name: "web.include-exporter-metrics",
Usage: "Include metrics about the exporter itself (promhttp_*, process_*, go_*).",
},
cli.BoolFlag{
Name: "log.debug",
Usage: "Enable more output in the logs, otherwise INFO.",
},
cli.StringFlag{
Name: "log.output",
Value: "stdout",
Usage: "Destination of our logs: stdout, stderr",
},
}

return app
}
54 changes: 4 additions & 50 deletions dnsbl_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"net/http"
"os"

"github.com/Luzilla/dnsbl_exporter/app"
"github.com/Luzilla/dnsbl_exporter/collector"
"github.com/Luzilla/dnsbl_exporter/config"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/urfave/cli"

log "github.com/sirupsen/logrus"

"github.com/prometheus/client_golang/prometheus/promhttp"
)

// The following are customized during build
Expand All @@ -30,54 +31,7 @@ func createRegistry() *prometheus.Registry {
}

func main() {
cli.VersionFlag = cli.BoolFlag{
Name: "version, V",
Usage: "Print the version information.",
}

app := cli.NewApp()
app.Name = exporterName
app.Version = exporterVersion
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config.dns-resolver",
Value: "127.0.0.1:53",
Usage: "IP address[:port] of the resolver to use.",
},
cli.StringFlag{
Name: "config.rbls",
Value: "./rbls.ini",
Usage: "Configuration file which contains RBLs",
},
cli.StringFlag{
Name: "config.targets",
Value: "./targets.ini",
Usage: "Configuration file which contains the targets to check.",
},
cli.StringFlag{
Name: "web.listen-address",
Value: ":9211",
Usage: "Address to listen on for web interface and telemetry.",
},
cli.StringFlag{
Name: "web.telemetry-path",
Value: "/metrics",
Usage: "Path under which to expose metrics.",
},
cli.BoolFlag{
Name: "web.include-exporter-metrics",
Usage: "Include metrics about the exporter itself (promhttp_*, process_*, go_*).",
},
cli.BoolFlag{
Name: "log.debug",
Usage: "Enable more output in the logs, otherwise INFO.",
},
cli.StringFlag{
Name: "log.output",
Value: "stdout",
Usage: "Destination of our logs: stdout, stderr",
},
}
app := app.NewApp(exporterName, exporterVersion)

app.Action = func(ctx *cli.Context) error {
// setup logging
Expand Down

0 comments on commit a96a718

Please sign in to comment.