mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:33:57 -04:00
CLI works
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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...)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user