From d3bb915de01b73c3c52529463bcf1fcaafcdff97 Mon Sep 17 00:00:00 2001 From: Dmitriy Kononov Date: Wed, 1 Apr 2020 22:46:40 +0600 Subject: [PATCH] adding ssl verification mode option --- README.md | 1 + pkg/sinks/elasticsearch.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b6c923..886af8e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pkg/sinks/elasticsearch.go b/pkg/sinks/elasticsearch.go index 78b3a4a..8538cda 100644 --- a/pkg/sinks/elasticsearch.go +++ b/pkg/sinks/elasticsearch.go @@ -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 }