Merge branch 'main' into alternate_storage

This commit is contained in:
Thomas Gruber
2021-10-04 15:49:46 +02:00
committed by GitHub
4 changed files with 20 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package sinks
import (
"context"
"crypto/tls"
"errors"
"fmt"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
@@ -19,14 +20,20 @@ type InfluxSink struct {
func (s *InfluxSink) connect() error {
var auth string
uri := fmt.Sprintf("http://%s:%s", s.host, s.port)
var uri string
if s.ssl {
uri = fmt.Sprintf("https://%s:%s", s.host, s.port)
} else {
uri = fmt.Sprintf("http://%s:%s", s.host, s.port)
}
if len(s.user) == 0 {
auth = s.password
} else {
auth = fmt.Sprintf("%s:%s", s.user, s.password)
}
log.Print("Using URI ", uri, " Org ", s.organization, " Bucket ", s.database)
s.client = influxdb2.NewClient(uri, auth)
s.client = influxdb2.NewClientWithOptions(uri, auth,
influxdb2.DefaultOptions().SetTLSConfig(&tls.Config{InsecureSkipVerify: true}))
s.writeApi = s.client.WriteAPIBlocking(s.organization, s.database)
return nil
}
@@ -45,6 +52,7 @@ func (s *InfluxSink) Init(config SinkConfig) error {
s.organization = config.Organization
s.user = config.User
s.password = config.Password
s.ssl = config.SSL
return s.connect()
}