fixed start loop

This commit is contained in:
Cody Lee 2022-12-11 13:00:40 -06:00
parent 4259d4f396
commit fded91ce40
No known key found for this signature in database
11 changed files with 49 additions and 31 deletions

View File

@ -56,6 +56,7 @@
# Pick which logs you want per-controller in the [unifi.controller] section. # Pick which logs you want per-controller in the [unifi.controller] section.
# This is a new feature. Feedback welcome! # This is a new feature. Feedback welcome!
[loki] [loki]
disable = true
url = "" url = ""
# The rest of this is advanced & optional. See wiki. # The rest of this is advanced & optional. See wiki.
user = "" user = ""

View File

@ -1,8 +1,11 @@
#influxdb #influxdb
INFLUXDB_HTTP_AUTH_ENABLED=true INFLUXDB_HTTP_AUTH_ENABLED=true
INFLUXDB_ADMIN_USER=unifi-poller INFLUXDB_ADMIN_USER=unpoller
INFLUXDB_ADMIN_PASSWORD=CHANGEME INFLUXDB_ADMIN_PASSWORD=CHANGEME
INFLUXDB_DB=unifi INFLUXDB_DB=unpoller
INFLUXDB_ORG=unpoller
INFLUXDB_BUCKET=unpoller
INFLUXDB_ADMIN_TOKEN=unpollersecret
#grafana #grafana
GRAFANA_USERNAME=admin GRAFANA_USERNAME=admin
@ -12,6 +15,6 @@ GRAFANA_PASSWORD=grafanaadmin
POLLER_TAG=latest POLLER_TAG=latest
POLLER_DEBUG=false POLLER_DEBUG=false
POLLER_SAVE_DPI=false POLLER_SAVE_DPI=false
UNIFI_USER=unifipoller UNIFI_USER=unpoller
UNIFI_PASS=set_this_on_your_controller UNIFI_PASS=set_this_on_your_controller
UNIFI_URL=https://127.0.0.1:8443 UNIFI_URL=https://127.0.0.1:8443

View File

@ -3,7 +3,7 @@ version: '3'
services: services:
influxdb: influxdb:
restart: always restart: always
image: influxdb:1.8 image: influxdb:2.5
ports: ports:
- '8086:8086' - '8086:8086'
volumes: volumes:
@ -11,8 +11,12 @@ services:
environment: environment:
- INFLUXDB_DB=${INFLUXDB_DB} - INFLUXDB_DB=${INFLUXDB_DB}
- INFLUXDB_HTTP_AUTH_ENABLED=${INFLUXDB_HTTP_AUTH_ENABLED} - INFLUXDB_HTTP_AUTH_ENABLED=${INFLUXDB_HTTP_AUTH_ENABLED}
- INFLUXDB_ADMIN_USER=${INFLUXDB_ADMIN_USER} - DOCKER_INFLUXDB_INIT_MODE=setup
- INFLUXDB_ADMIN_PASSWORD=${INFLUXDB_ADMIN_PASSWORD} - DOCKER_INFLUXDB_INIT_USERNAME=${INFLUXDB_ADMIN_USER}
- DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUXDB_ADMIN_PASSWORD}
- DOCKER_INFLUXDB_INIT_ORG=${INFLUXDB_ORG}
- DOCKER_INFLUXDB_INIT_BUCKET=${INFLUXDB_BUCKET}
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDB_ADMIN_TOKEN}
chronograf: chronograf:
image: chronograf:latest image: chronograf:latest
restart: always restart: always
@ -42,10 +46,17 @@ services:
unifi-poller: unifi-poller:
restart: always restart: always
image: ghcr.io/unpoller/unpoller:${POLLER_TAG} image: ghcr.io/unpoller/unpoller:${POLLER_TAG}
depends_on:
- grafana
- influxdb
- chronograf
environment: environment:
- UP_INFLUXDB_DB=${INFLUXDB_DB} - UP_INFLUXDB_DB=${INFLUXDB_DB}
- UP_INFLUXDB_USER=${INFLUXDB_ADMIN_USER} - UP_INFLUXDB_USER=${INFLUXDB_ADMIN_USER}
- UP_INFLUXDB_PASS=${INFLUXDB_ADMIN_PASSWORD} - UP_INFLUXDB_PASS=${INFLUXDB_ADMIN_PASSWORD}
- UP_INFLUXDB_ORG=${INFLUXDB_ORG}
- UP_INFLUXDB_BUCKET=${INFLUXDB_BUCKET}
- UP_INFLUXDB_AUTH_TOKEN=${INFLUXDB_ADMIN_TOKEN}
- UP_INFLUXDB_URL=http://influxdb:8086 - UP_INFLUXDB_URL=http://influxdb:8086
- UP_UNIFI_DEFAULT_USER=${UNIFI_USER} - UP_UNIFI_DEFAULT_USER=${UNIFI_USER}
- UP_UNIFI_DEFAULT_PASS=${UNIFI_PASS} - UP_UNIFI_DEFAULT_PASS=${UNIFI_PASS}

View File

@ -197,9 +197,6 @@ func (u *DatadogUnifi) Enabled() bool {
if u.Enable == nil || u.Config == nil { if u.Enable == nil || u.Config == nil {
return false return false
} }
if u.Collector == nil {
return false
}
return *u.Enable return *u.Enable
} }
@ -207,10 +204,10 @@ func (u *DatadogUnifi) Enabled() bool {
func (u *DatadogUnifi) Run(c poller.Collect) error { func (u *DatadogUnifi) Run(c poller.Collect) error {
u.Collector = c u.Collector = c
if !u.Enabled() { if !u.Enabled() {
u.Logf("DataDog config missing (or disabled), DataDog output disabled!") u.LogDebugf("DataDog config missing (or disabled), DataDog output disabled!")
return nil return nil
} }
u.Logf("Datadog is configured.") u.Logf("Datadog is enabled")
u.setConfigDefaults() u.setConfigDefaults()
var err error var err error

View File

@ -5,7 +5,6 @@ package influxunifi
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"log"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -53,11 +52,11 @@ type Config struct {
BatchSize uint `json:"batch_size,omitempty" toml:"batch_size,omitempty" xml:"batch_size" yaml:"batch_size"` BatchSize uint `json:"batch_size,omitempty" toml:"batch_size,omitempty" xml:"batch_size" yaml:"batch_size"`
// URL details which influxdb url to use to report metrics to. // URL details which influxdb url to use to report metrics to.
URL string `json:"url,omitempty" toml:"url,omitempty" xml:"url" yaml:"url"` URL string `json:"url,omitempty" toml:"url,omitempty" xml:"url" yaml:"url"`
// Disable when true will disable the influxdb output. // Disable when true will disable the influxdb output.
Disable bool `json:"disable" toml:"disable" xml:"disable,attr" yaml:"disable"` Disable bool `json:"disable" toml:"disable" xml:"disable,attr" yaml:"disable"`
// VerifySSL when true will require ssl verification. // VerifySSL when true will require ssl verification.
VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"` VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"`
// DeadPorts when true will save data for dead ports, for example ports that are down or disabled. // DeadPorts when true will save data for dead ports, for example ports that are down or disabled.
DeadPorts bool `json:"dead_ports" toml:"dead_ports" xml:"dead_ports" yaml:"dead_ports"` DeadPorts bool `json:"dead_ports" toml:"dead_ports" xml:"dead_ports" yaml:"dead_ports"`
} }
@ -105,8 +104,8 @@ func (u *InfluxUnifi) PollController() {
if u.IsVersion2 { if u.IsVersion2 {
version = "2" version = "2"
} }
log.Printf("[INFO] Poller->InfluxDB started, version: %s, interval: %v, dp: %v, db: %s, url: %s", u.Logf("Poller->InfluxDB started, version: %s, interval: %v, dp: %v, db: %s, url: %s, bucket: %s, org: %s",
version, interval, u.DeadPorts, u.DB, u.URL) version, interval, u.DeadPorts, u.DB, u.URL, u.Bucket, u.Org)
for u.LastCheck = range ticker.C { for u.LastCheck = range ticker.C {
metrics, err := u.Collector.Metrics(&poller.Filter{Name: "unifi"}) metrics, err := u.Collector.Metrics(&poller.Filter{Name: "unifi"})
@ -139,9 +138,6 @@ func (u *InfluxUnifi) Enabled() bool {
if u.Config == nil { if u.Config == nil {
return false return false
} }
if u.Collector == nil {
return false
}
return !u.Disable return !u.Disable
} }
@ -149,10 +145,12 @@ func (u *InfluxUnifi) Enabled() bool {
func (u *InfluxUnifi) Run(c poller.Collect) error { func (u *InfluxUnifi) Run(c poller.Collect) error {
u.Collector = c u.Collector = c
if !u.Enabled() { if !u.Enabled() {
u.Logf("InfluxDB config missing (or disabled), InfluxDB output disabled!") u.LogDebugf("InfluxDB config missing (or disabled), InfluxDB output disabled!")
return nil return nil
} }
u.Logf("InfluxDB enabled")
var err error var err error
u.setConfigDefaults() u.setConfigDefaults()

View File

@ -70,16 +70,20 @@ func (l *Loki) Enabled() bool {
if l.Config == nil { if l.Config == nil {
return false return false
} }
if l.URL == "" {
return false
}
return !l.Disable return !l.Disable
} }
// Run is fired from the poller library after the Config is unmarshalled. // Run is fired from the poller library after the Config is unmarshalled.
func (l *Loki) Run(collect poller.Collect) error { func (l *Loki) Run(collect poller.Collect) error {
l.Collect = collect l.Collect = collect
if l.Config == nil || l.URL == "" || !l.Enabled() { if !l.Enabled() {
l.Logf("Loki config missing (or disabled), Loki output disabled!") l.LogDebugf("Loki config missing (or disabled), Loki output disabled!")
return nil return nil
} }
l.Logf("Loki enabled")
l.ValidateConfig() l.ValidateConfig()

View File

@ -63,9 +63,12 @@ func (u *UnifiPoller) InitializeInputs() error {
for _, input := range inputs { for _, input := range inputs {
// This must return, or the app locks up here. // This must return, or the app locks up here.
u.LogDebugf("inititalizing input... %s", input.Name)
if err := input.Initialize(u); err != nil { if err := input.Initialize(u); err != nil {
u.LogDebugf("error initializing input ... %s", input.Name)
return err return err
} }
u.LogDebugf("input successfully initialized ... %s", input.Name)
} }
return nil return nil

View File

@ -87,9 +87,12 @@ func (u *UnifiPoller) runOutputMethods() (int, chan error) {
for _, o := range outputs { for _, o := range outputs {
if o != nil && o.Enabled() { if o != nil && o.Enabled() {
u.LogDebugf("output plugin enabled, starting run loop for %s", o.Name)
go func(o *Output) { go func(o *Output) {
err <- o.Run(u) // Run each output plugin err <- o.Run(u) // Run each output plugin
}(o) }(o)
} else {
u.LogDebugf("output plugin disabled for %s", o.Name)
} }
} }

View File

@ -94,5 +94,7 @@ func (u *UnifiPoller) Run() error {
return err return err
} }
u.LogDebugf("staring outputs")
return u.InitializeOutputs() return u.InitializeOutputs()
} }

View File

@ -121,9 +121,6 @@ func (u *promUnifi) Enabled() bool {
if u.Config == nil { if u.Config == nil {
return false return false
} }
if u.Collector == nil {
return false
}
return !u.Disable return !u.Disable
} }
@ -132,9 +129,10 @@ func (u *promUnifi) Enabled() bool {
func (u *promUnifi) Run(c poller.Collect) error { func (u *promUnifi) Run(c poller.Collect) error {
u.Collector = c u.Collector = c
if u.Config == nil || !u.Enabled() { if u.Config == nil || !u.Enabled() {
u.Logf("Prometheus config missing (or disabled), Prometheus HTTP listener disabled!") u.LogDebugf("Prometheus config missing (or disabled), Prometheus HTTP listener disabled!")
return nil return nil
} }
u.Logf("Prometheus is enabled")
u.Namespace = strings.Trim(strings.ReplaceAll(u.Namespace, "-", "_"), "_") u.Namespace = strings.Trim(strings.ReplaceAll(u.Namespace, "-", "_"), "_")
if u.Namespace == "" { if u.Namespace == "" {

View File

@ -73,9 +73,6 @@ func (s *Server) Enabled() bool {
if s.Config == nil { if s.Config == nil {
return false return false
} }
if s.Collect == nil {
return false
}
return s.Enable return s.Enable
} }
@ -83,9 +80,10 @@ func (s *Server) Enabled() bool {
func (s *Server) Run(c poller.Collect) error { func (s *Server) Run(c poller.Collect) error {
s.Collect = c s.Collect = c
if s.Config == nil || s.Port == 0 || s.HTMLPath == "" || !s.Enabled() { if s.Config == nil || s.Port == 0 || s.HTMLPath == "" || !s.Enabled() {
s.Logf("Internal web server disabled!") s.LogDebugf("Internal web server disabled!")
return nil return nil
} }
s.Logf("Internal web server enabled")
if _, err := os.Stat(s.HTMLPath); err != nil { if _, err := os.Stat(s.HTMLPath); err != nil {
return fmt.Errorf("problem with HTML path: %w", err) return fmt.Errorf("problem with HTML path: %w", err)