opentsdb: add tcp:// prefix if not present

closes #2299
This commit is contained in:
Cameron Sparr 2017-01-23 11:19:51 -08:00
parent 95bad9e55b
commit c3ae75730b
No known key found for this signature in database
GPG Key ID: 19E67263DCB25D0F
2 changed files with 6 additions and 2 deletions

View File

@ -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. - [#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. - [#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 - [#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] ## v1.1.2 [2016-12-12]

View File

@ -59,6 +59,9 @@ func ToLineFormat(tags map[string]string) string {
} }
func (o *OpenTSDB) Connect() error { 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 // Test Connection to OpenTSDB Server
u, err := url.Parse(o.Host) u, err := url.Parse(o.Host)
if err != nil { if err != nil {
@ -68,11 +71,11 @@ func (o *OpenTSDB) Connect() error {
uri := fmt.Sprintf("%s:%d", u.Host, o.Port) uri := fmt.Sprintf("%s:%d", u.Host, o.Port)
tcpAddr, err := net.ResolveTCPAddr("tcp", uri) tcpAddr, err := net.ResolveTCPAddr("tcp", uri)
if err != nil { 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) connection, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil { if err != nil {
return fmt.Errorf("OpenTSDB: Telnet connect fail") return fmt.Errorf("OpenTSDB Telnet connect fail: %s", err)
} }
defer connection.Close() defer connection.Close()
return nil return nil