Skip to content

Commit

Permalink
opentsdb: add tcp:// prefix if not present
Browse files Browse the repository at this point in the history
closes #2299
  • Loading branch information
sparrc committed Jan 23, 2017
1 parent 3de6bfb commit 3467dba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
7 changes: 5 additions & 2 deletions plugins/outputs/opentsdb/opentsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 3467dba

Please sign in to comment.