Skip to content

Commit

Permalink
Add support for SSL settings to ElasticSearch output plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
adityacs committed Oct 30, 2017
1 parent 53b13a2 commit 7594c61
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion plugins/outputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"strings"
"time"

"net/http"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/outputs"
Expand All @@ -16,6 +16,7 @@ import (

type Elasticsearch struct {
URLs []string `toml:"urls"`
Scheme string
IndexName string
Username string
Password string
Expand All @@ -25,6 +26,10 @@ type Elasticsearch struct {
ManageTemplate bool
TemplateName string
OverwriteTemplate bool
SSLCA string `toml:"ssl_ca"` // Path to CA file
SSLCert string `toml:"ssl_cert"` // Path to host cert file
SSLKey string `toml:"ssl_key"` // Path to cert key file
InsecureSkipVerify bool // Use SSL but skip chain & host verification
Client *elastic.Client
}

Expand Down Expand Up @@ -76,7 +81,22 @@ func (a *Elasticsearch) Connect() error {

var clientOptions []elastic.ClientOptionFunc

tlsCfg, err := internal.GetTLSConfig(e.SSLCert, e.SSLKey, e.SSLCA, e.InsecureSkipVerify)
if err != nil {
return nil, err
}
tr := &http.Transport{
ResponseHeaderTimeout: a.Timeout.Duration,
TLSClientConfig: tlsCfg,
}

httpclient := &http.Client{
Transport: tr,
Timeout: a.Timeout.Duration,
}

clientOptions = append(clientOptions,
elastic.SetHttpClient(httpclient)
elastic.SetSniff(a.EnableSniffer),
elastic.SetURL(a.URLs...),
elastic.SetHealthcheckInterval(a.HealthCheckInterval.Duration),
Expand Down

0 comments on commit 7594c61

Please sign in to comment.