From a852e8106ef86d529b8d3e639cc904df3c661da1 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 c0c96476a..a3c26132a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,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