mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-25 15:09:05 +01:00
Add SSL to InfluxDB sink
This commit is contained in:
parent
34585d88df
commit
586c6c12ac
@ -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()
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ type SinkConfig struct {
|
||||
Password string `json:"password"`
|
||||
Organization string `json:"organization"`
|
||||
Type string `json:"type"`
|
||||
SSL bool `json:"ssl"`
|
||||
}
|
||||
|
||||
type Sink struct {
|
||||
@ -21,6 +22,7 @@ type Sink struct {
|
||||
password string
|
||||
database string
|
||||
organization string
|
||||
ssl bool
|
||||
}
|
||||
|
||||
type SinkFuncs interface {
|
||||
|
Loading…
Reference in New Issue
Block a user