adding ssl verification mode option

This commit is contained in:
Dmitriy Kononov
2020-04-01 22:46:40 +06:00
parent 78d9b77848
commit d3bb915de0
2 changed files with 14 additions and 2 deletions
+1
View File
@@ -110,6 +110,7 @@ receivers:
password: # optional
cloudID: # optional
apiKey: # optional
sslVerificationMode: none # optional, for self signed ssl certificate
# If set to true, it allows updating the same document in ES (might be useful handling count)
useEventID: true|false
layout: # Optional
+13 -2
View File
@@ -3,10 +3,12 @@ package sinks
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"github.com/elastic/go-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7/esapi"
"github.com/opsgenie/kubernetes-event-exporter/pkg/kube"
"net/http"
)
type ElasticsearchConfig struct {
@@ -19,16 +21,25 @@ type ElasticsearchConfig struct {
// Indexing preferences
UseEventID bool `yaml:"useEventID"`
Index string `yaml:"index"`
// SSL settings
SslVerificationMode string `yaml:"sslVerificationMode"`
}
func NewElasticsearch(cfg *ElasticsearchConfig) (*Elasticsearch, error) {
client, err := elasticsearch.NewClient(elasticsearch.Config{
eCfg := elasticsearch.Config{
Addresses: cfg.Hosts,
Username: cfg.Username,
Password: cfg.Password,
CloudID: cfg.CloudID,
APIKey: cfg.APIKey,
})
}
if cfg.SslVerificationMode == "none" {
eCfg.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
client, err := elasticsearch.NewClient(eCfg)
if err != nil {
return nil, err
}