69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
|
// influxdb
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
// "time"
|
||
|
|
||
|
influxdb "github.com/influxdata/influxdb/client/v2"
|
||
|
)
|
||
|
|
||
|
func writeStats(mimp *MongoImp) {
|
||
|
if opts.Debug {
|
||
|
fmt.Printf("writing to influxdb server: %s", opts.Influxdb)
|
||
|
}
|
||
|
|
||
|
c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{
|
||
|
Addr: opts.Influxdb,
|
||
|
})
|
||
|
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": mimp.Host}
|
||
|
fields := map[string]interface{}{
|
||
|
"banner_legit": mimp.Banner.Legit,
|
||
|
"banner_spam": mimp.Banner.Spam,
|
||
|
"banner_virus": mimp.Banner.Virus,
|
||
|
"auth_legit": mimp.Auth.Legit,
|
||
|
"auth_spam": mimp.Auth.Spam,
|
||
|
"auth_virus": mimp.Auth.Virus,
|
||
|
"content_legit": mimp.Content.Legit,
|
||
|
"content_spam": mimp.Content.Spam,
|
||
|
"content_virus": mimp.Content.Virus,
|
||
|
"data_legit": mimp.Data.Legit,
|
||
|
"data_spam": mimp.Data.Spam,
|
||
|
"data_virus": mimp.Data.Virus,
|
||
|
"mailfrom_legit": mimp.Mailfrom.Legit,
|
||
|
"mailfrom_spam": mimp.Mailfrom.Spam,
|
||
|
"mailfrom_virus": mimp.Mailfrom.Virus,
|
||
|
"rcptto_legit": mimp.Rcptto.Legit,
|
||
|
"rcptto_spam": mimp.Rcptto.Spam,
|
||
|
"rcptto_virus": mimp.Rcptto.Virus,
|
||
|
"rate_content": mimp.Rate.Contentp,
|
||
|
"rate_smtp": mimp.Rate.Smtpp,
|
||
|
"rate_total": mimp.Rate.Totalp,
|
||
|
}
|
||
|
pt, err := influxdb.NewPoint("cloudmark", tags, fields, mimp.Date)
|
||
|
if err != nil {
|
||
|
fmt.Printf("Error: %+v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
bp.AddPoint(pt)
|
||
|
|
||
|
// Write the batch
|
||
|
c.Write(bp)
|
||
|
}
|