From 5ce4a2d05cfe5a7b77ed9325e6192c3023eef6f6 Mon Sep 17 00:00:00 2001 From: Maximilien Richer Date: Wed, 11 Jul 2018 17:50:03 +0200 Subject: [PATCH] Add HTTP authentification to influxdb metric backend --- docs/configuration/metrics.md | 14 ++++++++++++++ metrics/influxdb.go | 4 +++- types/types.go | 4 +++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/configuration/metrics.md b/docs/configuration/metrics.md index 8ff1cb4b0..33a05fb8a 100644 --- a/docs/configuration/metrics.md +++ b/docs/configuration/metrics.md @@ -104,6 +104,20 @@ # protocol = "udp" + # InfluxDB's username + # + # Optional + # Default: "" (no username) + # + username = "" + + # InfluxDB's password + # + # Optional + # Default: "" (no password) + # + password = "" + # InfluxDB push interval # # Optional diff --git a/metrics/influxdb.go b/metrics/influxdb.go index ea5f92b88..5dec81374 100644 --- a/metrics/influxdb.go +++ b/metrics/influxdb.go @@ -157,7 +157,9 @@ func (w *influxDBWriter) Write(bp influxdb.BatchPoints) error { func (w *influxDBWriter) initWriteClient() (influxdb.Client, error) { if w.config.Protocol == "http" { return influxdb.NewHTTPClient(influxdb.HTTPConfig{ - Addr: w.config.Address, + Addr: w.config.Address, + Username: w.config.Username, + Password: w.config.Password, }) } diff --git a/types/types.go b/types/types.go index 9c7e076d7..5591afc23 100644 --- a/types/types.go +++ b/types/types.go @@ -455,13 +455,15 @@ type Statsd struct { PushInterval string `description:"StatsD push interval" export:"true"` } -// InfluxDB contains address and metrics pushing interval configuration +// InfluxDB contains address, login and metrics pushing interval configuration type InfluxDB struct { Address string `description:"InfluxDB address"` Protocol string `description:"InfluxDB address protocol (udp or http)"` PushInterval string `description:"InfluxDB push interval" export:"true"` Database string `description:"InfluxDB database used when protocol is http" export:"true"` RetentionPolicy string `description:"InfluxDB retention policy used when protocol is http" export:"true"` + Username string `description:"InfluxDB username (only with http)" export:"true"` + Password string `description:"InfluxDB password (only with http)" export:"true"` } // Buckets holds Prometheus Buckets