From de26b44c1541dd985a1c9251d7cf18d94b8e85e1 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Fri, 26 Feb 2016 16:26:43 +0000 Subject: [PATCH] influxdb output: try to connect on write if there are no conns --- plugins/outputs/influxdb/influxdb.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/outputs/influxdb/influxdb.go b/plugins/outputs/influxdb/influxdb.go index 60d235511..db9926bbc 100644 --- a/plugins/outputs/influxdb/influxdb.go +++ b/plugins/outputs/influxdb/influxdb.go @@ -129,6 +129,7 @@ func (i *InfluxDB) Connect() error { if e != nil { log.Println("Database creation failed: " + e.Error()) + continue } conns = append(conns, c) @@ -156,6 +157,12 @@ func (i *InfluxDB) Description() string { // Choose a random server in the cluster to write to until a successful write // occurs, logging each unsuccessful. If all servers fail, return error. func (i *InfluxDB) Write(metrics []telegraf.Metric) error { + if len(i.conns) == 0 { + err := i.Connect() + if err != nil { + return err + } + } bp, err := client.NewBatchPoints(client.BatchPointsConfig{ Database: i.Database, Precision: i.Precision,