mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:33:57 -04:00
add integration test guard;
datadog integration test works influx package tests update unifi version golanglint-ci and address *all* issues. all tests pass bump unifi version
This commit is contained in:
@@ -78,6 +78,7 @@ func (u *promUnifi) exportClientDPI(r report, v any, appTotal, catTotal totalsDP
|
||||
s, ok := v.(*unifi.DPITable)
|
||||
if !ok {
|
||||
u.LogErrorf("invalid type given to ClientsDPI: %T", v)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -166,6 +167,7 @@ func fillDPIMapTotals(m totalsDPImap, name, controller, site string, dpi unifi.D
|
||||
|
||||
if _, ok := m[controller][site][name]; !ok {
|
||||
m[controller][site][name] = dpi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -54,11 +54,11 @@ var _ poller.OutputPlugin = &promUnifi{}
|
||||
type Config struct {
|
||||
// If non-empty, each of the collected metrics is prefixed by the
|
||||
// provided string and an underscore ("_").
|
||||
Namespace string `json:"namespace" toml:"namespace" xml:"namespace" yaml:"namespace"`
|
||||
Namespace string `json:"namespace" toml:"namespace" xml:"namespace" yaml:"namespace"`
|
||||
HTTPListen string `json:"http_listen" toml:"http_listen" xml:"http_listen" yaml:"http_listen"`
|
||||
// If these are provided, the app will attempt to listen with an SSL connection.
|
||||
SSLCrtPath string `json:"ssl_cert_path" toml:"ssl_cert_path" xml:"ssl_cert_path" yaml:"ssl_cert_path"`
|
||||
SSLKeyPath string `json:"ssl_key_path" toml:"ssl_key_path" xml:"ssl_key_path" yaml:"ssl_key_path"`
|
||||
SSLKeyPath string `json:"ssl_key_path" toml:"ssl_key_path" xml:"ssl_key_path" yaml:"ssl_key_path"`
|
||||
// Buffer is a channel buffer.
|
||||
// Default is probably 50. Seems fast there; try 1 to see if CPU usage goes down?
|
||||
Buffer int `json:"buffer" toml:"buffer" xml:"buffer" yaml:"buffer"`
|
||||
@@ -67,7 +67,7 @@ type Config struct {
|
||||
// and the collected metrics will be incomplete. Possibly, no metrics
|
||||
// will be collected at all.
|
||||
ReportErrors bool `json:"report_errors" toml:"report_errors" xml:"report_errors" yaml:"report_errors"`
|
||||
Disable bool `json:"disable" toml:"disable" xml:"disable" yaml:"disable"`
|
||||
Disable bool `json:"disable" toml:"disable" xml:"disable" yaml:"disable"`
|
||||
// Save data for dead ports? ie. ports that are down or disabled.
|
||||
DeadPorts bool `json:"dead_ports" toml:"dead_ports" xml:"dead_ports" yaml:"dead_ports"`
|
||||
}
|
||||
@@ -121,12 +121,15 @@ func (u *promUnifi) DebugOutput() (bool, error) {
|
||||
if u == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if !u.Enabled() {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if u.HTTPListen == "" {
|
||||
return false, fmt.Errorf("invalid listen string")
|
||||
}
|
||||
|
||||
// check the port
|
||||
parts := strings.Split(u.HTTPListen, ":")
|
||||
if len(parts) != 2 {
|
||||
@@ -137,7 +140,9 @@ func (u *promUnifi) DebugOutput() (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
_ = ln.Close()
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -145,9 +150,11 @@ func (u *promUnifi) Enabled() bool {
|
||||
if u == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if u.Config == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return !u.Disable
|
||||
}
|
||||
|
||||
@@ -157,8 +164,10 @@ func (u *promUnifi) Run(c poller.Collect) error {
|
||||
u.Collector = c
|
||||
if u.Config == nil || !u.Enabled() {
|
||||
u.LogDebugf("Prometheus config missing (or disabled), Prometheus HTTP listener disabled!")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
u.Logf("Prometheus is enabled")
|
||||
|
||||
u.Namespace = strings.Trim(strings.ReplaceAll(u.Namespace, "-", "_"), "_")
|
||||
@@ -200,9 +209,11 @@ func (u *promUnifi) Run(c poller.Collect) error {
|
||||
switch u.SSLKeyPath == "" && u.SSLCrtPath == "" {
|
||||
case true:
|
||||
u.Logf("Prometheus exported at http://%s/ - namespace: %s", u.HTTPListen, u.Namespace)
|
||||
|
||||
return http.ListenAndServe(u.HTTPListen, mux)
|
||||
default:
|
||||
u.Logf("Prometheus exported at https://%s/ - namespace: %s", u.HTTPListen, u.Namespace)
|
||||
|
||||
return http.ListenAndServeTLS(u.HTTPListen, u.SSLCrtPath, u.SSLKeyPath, mux)
|
||||
}
|
||||
}
|
||||
@@ -249,7 +260,7 @@ func (u *promUnifi) ScrapeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (u *promUnifi) DefaultHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func (u *promUnifi) DefaultHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(poller.AppName + "\n"))
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func (u *promUnifi) Logf(msg string, v ...any) {
|
||||
Msg: fmt.Sprintf(msg, v...),
|
||||
Tags: map[string]string{"type": "info"},
|
||||
})
|
||||
|
||||
if u.Collector != nil {
|
||||
u.Collector.Logf(msg, v...)
|
||||
}
|
||||
@@ -26,6 +27,7 @@ func (u *promUnifi) LogErrorf(msg string, v ...any) {
|
||||
Msg: fmt.Sprintf(msg, v...),
|
||||
Tags: map[string]string{"type": "error"},
|
||||
})
|
||||
|
||||
if u.Collector != nil {
|
||||
u.Collector.LogErrorf(msg, v...)
|
||||
}
|
||||
@@ -38,6 +40,7 @@ func (u *promUnifi) LogDebugf(msg string, v ...any) {
|
||||
Msg: fmt.Sprintf(msg, v...),
|
||||
Tags: map[string]string{"type": "debug"},
|
||||
})
|
||||
|
||||
if u.Collector != nil {
|
||||
u.Collector.LogDebugf(msg, v...)
|
||||
}
|
||||
|
||||
@@ -143,9 +143,11 @@ func (u *promUnifi) exportPDU(r report, d *unifi.PDU) {
|
||||
if d.OutletACPowerConsumption.Txt != "" {
|
||||
r.send([]*metric{{u.Device.OutletACPowerConsumption, gauge, d.OutletACPowerConsumption, labels}})
|
||||
}
|
||||
|
||||
if d.PowerSource.Txt != "" {
|
||||
r.send([]*metric{{u.Device.PowerSource, gauge, d.PowerSource, labels}})
|
||||
}
|
||||
|
||||
if d.TotalMaxPower.Txt != "" {
|
||||
r.send([]*metric{{u.Device.TotalMaxPower, gauge, d.TotalMaxPower, labels}})
|
||||
}
|
||||
@@ -241,7 +243,6 @@ func (u *promUnifi) exportPDUPrtTable(r report, labels []string, pt []unifi.Port
|
||||
func (u *promUnifi) exportPDUOutletTable(r report, labels []string, ot []unifi.OutletTable, oto []unifi.OutletOverride) {
|
||||
// Per-outlet data on a switch
|
||||
for _, o := range ot {
|
||||
|
||||
// Copy labels, and add four new ones.
|
||||
labelOutlet := []string{
|
||||
labels[2] + " Outlet " + o.Index.Txt, o.Index.Txt,
|
||||
@@ -261,7 +262,6 @@ func (u *promUnifi) exportPDUOutletTable(r report, labels []string, ot []unifi.O
|
||||
|
||||
// Per-outlet data on a switch
|
||||
for _, o := range oto {
|
||||
|
||||
// Copy labels, and add four new ones.
|
||||
labelOutlet := []string{
|
||||
labels[2] + " Outlet Override " + o.Index.Txt, o.Index.Txt,
|
||||
|
||||
@@ -79,6 +79,7 @@ func (u *promUnifi) exportSiteDPI(r report, v any) {
|
||||
s, ok := v.(*unifi.DPITable)
|
||||
if !ok {
|
||||
u.LogErrorf("invalid type given to SiteDPI: %T", v)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package promunifi
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -87,7 +86,7 @@ func (u *promUnifi) exportUSG(r report, d *unifi.USG) {
|
||||
}
|
||||
|
||||
for k, v := range d.SystemStats.Temps {
|
||||
temp, _ := strconv.ParseInt(strings.Split(v, " ")[0], 10, 64)
|
||||
temp := v.CelsiusInt64()
|
||||
k = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(k, " ", "_"), ")", ""), "(", "")
|
||||
|
||||
if k = strings.ToLower(k); temp != 0 && k != "" {
|
||||
|
||||
@@ -9,11 +9,13 @@ func (u *promUnifi) exportUXG(r report, d *unifi.UXG) {
|
||||
if !d.Adopted.Val || d.Locating.Val {
|
||||
return
|
||||
}
|
||||
var gw *unifi.Gw = nil
|
||||
|
||||
var gw *unifi.Gw
|
||||
if d.Stat != nil {
|
||||
gw = d.Stat.Gw
|
||||
}
|
||||
var sw *unifi.Sw = nil
|
||||
|
||||
var sw *unifi.Sw
|
||||
if d.Stat != nil {
|
||||
sw = d.Stat.Sw
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user