add example config

This commit is contained in:
davidnewhall2 2020-06-24 15:12:51 -07:00
parent b93b76e1de
commit 16fde27436
2 changed files with 28 additions and 9 deletions

View File

@ -3,3 +3,22 @@
Loki Output Plugin for UniFi Poller
This plugin writes UniFi Events and IDS data to Loki. Maybe Alarms too.
```
[loki]
# URL is the only required setting for Loki.
url = "http://192.168.3.2:3100"
# How often to poll UniFi and report to Loki.
interval = "2m"
# How long to wait for Loki responses.
timeout = "5s"
# Set these to use basic auth.
user = ""
pass = ""
# Used for auth-less multi-tenant.
tenant_id = ""
```

View File

@ -12,8 +12,8 @@ import (
const (
maxInterval = time.Hour
minInterval = 10 * time.Second
defaultInterval = time.Minute
defaultTimeout = 8 * time.Second
defaultTimeout = 10 * time.Second
defaultInterval = 2 * time.Minute
)
const (
@ -65,16 +65,16 @@ func (l *Loki) Run(collect poller.Collect) error {
return nil
}
l.validateConfig()
l.ValidateConfig()
l.PollController()
l.LogErrorf("Loki Output Plugin Stopped!")
return nil
}
// validateConfig sets initial "last" update time. Also creates an http client,
// ValidateConfig sets initial "last" update time. Also creates an http client,
// makes sure URL is sane, and sets interval within min/max limits.
func (l *Loki) validateConfig() {
func (l *Loki) ValidateConfig() {
if l.Interval.Duration > maxInterval {
l.Interval.Duration = maxInterval
} else if l.Interval.Duration < minInterval {
@ -107,7 +107,7 @@ func (l *Loki) pollController(start time.Time) error {
return errors.Wrap(err, "event fetch for Loki failed")
}
report := &Report{
r := &Report{
Events: events,
Start: start,
Logger: l.Collect,
@ -115,7 +115,7 @@ func (l *Loki) pollController(start time.Time) error {
Last: l.last,
}
return l.ReportEvents(report)
return l.ReportEvents(r)
}
// ReportEvents should be easy to test.
@ -131,8 +131,8 @@ func (l *Loki) ReportEvents(r *Report) error {
}
l.last = r.Start
l.Logf("Events sent to Loki. Events: %d, IDS: %d, Dur: %v", r.Eve, r.IDS,
time.Since(l.last).Round(time.Millisecond))
l.Logf("Events sent to Loki. Events: %d, IDS: %d, Dur: %v",
r.Eve, r.IDS, time.Since(l.last).Round(time.Millisecond))
return nil
}