From c3ae75730b2a7098bf4f1085a7eb03f571d52202 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Mon, 23 Jan 2017 11:19:51 -0800 Subject: [PATCH] opentsdb: add tcp:// prefix if not present closes #2299 --- CHANGELOG.md | 1 + plugins/outputs/opentsdb/opentsdb.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8919669d1..a211bf95e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ plugins, not just statsd. - [#1975](https://github.com/influxdata/telegraf/issues/1975) & [#2102](https://github.com/influxdata/telegraf/issues/2102): Fix thread-safety when using multiple instances of the statsd input plugin. - [#2027](https://github.com/influxdata/telegraf/issues/2027): docker input: interface conversion panic fix. - [#1814](https://github.com/influxdata/telegraf/issues/1814): snmp: ensure proper context is present on error messages +- [#2299](https://github.com/influxdata/telegraf/issues/2299): opentsdb: add tcp:// prefix if no scheme provided. ## v1.1.2 [2016-12-12] diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index 84ff99058..ac4d1224e 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -59,6 +59,9 @@ func ToLineFormat(tags map[string]string) string { } func (o *OpenTSDB) Connect() error { + if !strings.HasPrefix(o.Host, "http") && !strings.HasPrefix(o.Host, "tcp") { + o.Host = "tcp://" + o.Host + } // Test Connection to OpenTSDB Server u, err := url.Parse(o.Host) if err != nil { @@ -68,11 +71,11 @@ func (o *OpenTSDB) Connect() error { uri := fmt.Sprintf("%s:%d", u.Host, o.Port) tcpAddr, err := net.ResolveTCPAddr("tcp", uri) if err != nil { - return fmt.Errorf("OpenTSDB: TCP address cannot be resolved") + return fmt.Errorf("OpenTSDB TCP address cannot be resolved: %s", err) } connection, err := net.DialTCP("tcp", nil, tcpAddr) if err != nil { - return fmt.Errorf("OpenTSDB: Telnet connect fail") + return fmt.Errorf("OpenTSDB Telnet connect fail: %s", err) } defer connection.Close() return nil