CLI works

This commit is contained in:
Cody Lee
2022-12-22 18:16:43 -06:00
parent db9bcd5687
commit 3768c53512
16 changed files with 126 additions and 33 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"reflect"
"strings"
"sync"
@@ -118,7 +117,7 @@ func init() { // nolint: gochecknoinits
})
}
func (u *promUnifi) DebugOutput(l poller.Logger) (bool, error) {
func (u *promUnifi) DebugOutput() (bool, error) {
if u == nil {
return true, nil
}
@@ -129,16 +128,17 @@ func (u *promUnifi) DebugOutput(l poller.Logger) (bool, error) {
return false, fmt.Errorf("invalid listen string")
}
// check the port
httpListenURL, err := url.Parse(u.HTTPListen)
if err != nil {
return false, err
parts := strings.Split(u.HTTPListen, ":")
if len(parts) != 2 {
return false, fmt.Errorf("invalid listen address: %s (must be of the form \"IP:Port\"", u.HTTPListen)
}
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%s", httpListenURL.Host, httpListenURL.Port()))
ln, err := net.Listen("tcp", u.HTTPListen)
if err != nil {
return false, err
}
_ = ln.Close()
return false, nil
return true, nil
}
func (u *promUnifi) Enabled() bool {

View File

@@ -14,7 +14,9 @@ func (u *promUnifi) Logf(msg string, v ...any) {
Msg: fmt.Sprintf(msg, v...),
Tags: map[string]string{"type": "info"},
})
u.Collector.Logf(msg, v...)
if u.Collector != nil {
u.Collector.Logf(msg, v...)
}
}
// LogErrorf logs an error message.
@@ -24,7 +26,9 @@ func (u *promUnifi) LogErrorf(msg string, v ...any) {
Msg: fmt.Sprintf(msg, v...),
Tags: map[string]string{"type": "error"},
})
u.Collector.LogErrorf(msg, v...)
if u.Collector != nil {
u.Collector.LogErrorf(msg, v...)
}
}
// LogDebugf logs a debug message.
@@ -34,5 +38,7 @@ func (u *promUnifi) LogDebugf(msg string, v ...any) {
Msg: fmt.Sprintf(msg, v...),
Tags: map[string]string{"type": "debug"},
})
u.Collector.LogDebugf(msg, v...)
if u.Collector != nil {
u.Collector.LogDebugf(msg, v...)
}
}