From 16fde27436aadfb9373285908de80c07a758c8ee Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Wed, 24 Jun 2020 15:12:51 -0700 Subject: [PATCH] add example config --- integrations/lokiunifi/README.md | 19 +++++++++++++++++++ integrations/lokiunifi/loki.go | 18 +++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/integrations/lokiunifi/README.md b/integrations/lokiunifi/README.md index 969d86df..b6239f43 100644 --- a/integrations/lokiunifi/README.md +++ b/integrations/lokiunifi/README.md @@ -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 = "" +``` diff --git a/integrations/lokiunifi/loki.go b/integrations/lokiunifi/loki.go index 499834cf..da437020 100644 --- a/integrations/lokiunifi/loki.go +++ b/integrations/lokiunifi/loki.go @@ -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 }