Rename variables
This commit is contained in:
parent
a4a61c4b15
commit
2376557186
|
|
@ -11,7 +11,7 @@ HBREPO="golift/homebrew-mugs"
|
||||||
MAINT="David Newhall II <david at sleepers dot pro>"
|
MAINT="David Newhall II <david at sleepers dot pro>"
|
||||||
VENDOR="Go Lift <code at golift dot io>"
|
VENDOR="Go Lift <code at golift dot io>"
|
||||||
DESC="Polls a UniFi controller and exports metrics to InfluxDB"
|
DESC="Polls a UniFi controller and exports metrics to InfluxDB"
|
||||||
GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -e G101 "
|
GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll"
|
||||||
# Example must exist at examples/$CONFIG_FILE.example
|
# Example must exist at examples/$CONFIG_FILE.example
|
||||||
CONFIG_FILE="up.conf"
|
CONFIG_FILE="up.conf"
|
||||||
LICENSE="MIT"
|
LICENSE="MIT"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
influx "github.com/influxdata/influxdb1-client/v2"
|
influx "github.com/influxdata/influxdb1-client/v2"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"golift.io/unifi"
|
"golift.io/unifi"
|
||||||
"gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is injected by the Makefile
|
// Version is injected by the Makefile
|
||||||
|
|
@ -24,13 +24,13 @@ var Version = "development"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// App defaults in case they're missing from the config.
|
// App defaults in case they're missing from the config.
|
||||||
defaultInterval = 30 * time.Second
|
defaultInterval = 30 * time.Second
|
||||||
defaultInfxDb = "unifi"
|
defaultInfluxDB = "unifi"
|
||||||
defaultInfxUser = "unifi"
|
defaultInfluxUser = "unifi"
|
||||||
defaultInfxPass = "unifi"
|
defaultInfluxPass = "unifi"
|
||||||
defaultInfxURL = "http://127.0.0.1:8086"
|
defaultInfluxURL = "http://127.0.0.1:8086"
|
||||||
defaultUnifUser = "influx"
|
defaultUnifiUser = "influx"
|
||||||
defaultUnifURL = "https://127.0.0.1:8443"
|
defaultUnifiURL = "https://127.0.0.1:8443"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ENVConfigPrefix is the prefix appended to an env variable tag
|
// ENVConfigPrefix is the prefix appended to an env variable tag
|
||||||
|
|
|
||||||
|
|
@ -16,16 +16,17 @@ import (
|
||||||
// Parses flags, parses config and executes Run().
|
// Parses flags, parses config and executes Run().
|
||||||
func Start() error {
|
func Start() error {
|
||||||
log.SetFlags(log.LstdFlags)
|
log.SetFlags(log.LstdFlags)
|
||||||
up := &UnifiPoller{Flag: &Flag{},
|
up := &UnifiPoller{
|
||||||
|
Flag: &Flag{},
|
||||||
Config: &Config{
|
Config: &Config{
|
||||||
// Preload our defaults.
|
// Preload our defaults.
|
||||||
InfluxURL: defaultInfxURL,
|
InfluxURL: defaultInfluxURL,
|
||||||
InfluxUser: defaultInfxUser,
|
InfluxUser: defaultInfluxUser,
|
||||||
InfluxPass: defaultInfxPass,
|
InfluxPass: defaultInfluxPass,
|
||||||
InfluxDB: defaultInfxDb,
|
InfluxDB: defaultInfluxDB,
|
||||||
UnifiUser: defaultUnifUser,
|
UnifiUser: defaultUnifiUser,
|
||||||
UnifiPass: os.Getenv("UNIFI_PASSWORD"), // deprecated name.
|
UnifiPass: os.Getenv("UNIFI_PASSWORD"), // deprecated name.
|
||||||
UnifiBase: defaultUnifURL,
|
UnifiBase: defaultUnifiURL,
|
||||||
Interval: Duration{defaultInterval},
|
Interval: Duration{defaultInterval},
|
||||||
Sites: []string{"all"},
|
Sites: []string{"all"},
|
||||||
}}
|
}}
|
||||||
|
|
@ -53,14 +54,14 @@ func Start() error {
|
||||||
func (f *Flag) Parse(args []string) {
|
func (f *Flag) Parse(args []string) {
|
||||||
f.FlagSet = pflag.NewFlagSet("unifi-poller", pflag.ExitOnError)
|
f.FlagSet = pflag.NewFlagSet("unifi-poller", pflag.ExitOnError)
|
||||||
f.Usage = func() {
|
f.Usage = func() {
|
||||||
fmt.Println("Usage: unifi-poller [--config=filepath] [--version]")
|
fmt.Println("Usage: unifi-poller [--config=/path/to/up.conf] [--version]")
|
||||||
f.PrintDefaults()
|
f.PrintDefaults()
|
||||||
}
|
}
|
||||||
f.StringVarP(&f.DumpJSON, "dumpjson", "j", "",
|
f.StringVarP(&f.DumpJSON, "dumpjson", "j", "",
|
||||||
"This debug option prints a json payload and exits. See man page for more info.")
|
"This debug option prints a json payload and exits. See man page for more info.")
|
||||||
f.StringVarP(&f.ConfigFile, "config", "c", DefaultConfFile, "Poller config file path.")
|
f.StringVarP(&f.ConfigFile, "config", "c", DefaultConfFile, "Poller config file path.")
|
||||||
f.BoolVarP(&f.ShowVer, "version", "v", false, "Print the version and exit.")
|
f.BoolVarP(&f.ShowVer, "version", "v", false, "Print the version and exit.")
|
||||||
_ = f.FlagSet.Parse(args)
|
_ = f.FlagSet.Parse(args) // pflag.ExitOnError means this will never return error.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run invokes all the application logic and routines.
|
// Run invokes all the application logic and routines.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue