diff --git a/influxdb.go b/influxdb.go new file mode 100644 index 0000000..e9daead --- /dev/null +++ b/influxdb.go @@ -0,0 +1,51 @@ +// influxdb +package main + +import ( + "fmt" + "time" + + influxdb "github.com/influxdata/influxdb/client/v2" +) + +func writeStats(start time.Time, stop time.Duration) { + if opts.Debug { + fmt.Printf("writing to influxdb server: %s", opts.Influxdb) + } + + c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{ + Addr: opts.Influxdb, + Timeout: 2 * time.Second, + }) + if err != nil { + fmt.Printf("Error: %+v\n", err) + return + } + defer c.Close() + + bp, err := influxdb.NewBatchPoints(influxdb.BatchPointsConfig{ + Database: "dovecot", + Precision: "s", + }) + if err != nil { + fmt.Printf("Error: %+v\n", err) + return + } + + tags := map[string]string{"server": opts.Hostname} + fields := map[string]interface{}{ + "LoginOK": countOK, + "LoginTOT": countTOT, + "stop": stop.Seconds(), + } + pt, err := influxdb.NewPoint("llday", tags, fields, start) + if err != nil { + fmt.Printf("Error: %+v\n", err) + return + } + + bp.AddPoint(pt) + + // Write the batch + c.Write(bp) +} diff --git a/lastlogin_consolidate.go b/lastlogin_consolidate.go index 16d2648..226b50b 100644 --- a/lastlogin_consolidate.go +++ b/lastlogin_consolidate.go @@ -12,7 +12,7 @@ import ( ) const ( - _VERSION = "v1.2.0" + _VERSION = "v1.2.1" _tformat = "2006-01-02" _24h = (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59) _10m = (time.Minute * 10)