Skip to content

Commit

Permalink
Add support for RethinkDB 1.0 handshake protocol (#2963)
Browse files Browse the repository at this point in the history
Allow rethinkdb input plugin to work with RethinkDB 2.3.5+ databases that requires username,password authorization and Handshake protocol v1.0

* remove top level header not required in sample config

* remove top level header not required in sample config
  • Loading branch information
vodolaz095 authored and danielnelson committed Jun 26, 2017
1 parent f070f14 commit ab876bb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/zensqlmonitor/go-mssqldb ffe5510c6fa5e15e6d983210ab501c815b56b363
golang.org/x/crypto dc137beb6cce2043eb6b5f223ab8bf51c32459f4
golang.org/x/net f2499483f923065a842d38eb4c7f1927e6fc6e6d
golang.org/x/text 506f9d5c962f284575e88337e7d9296d27e729d3
gopkg.in/dancannon/gorethink.v1 edc7a6a68e2d8015f5ffe1b2560eed989f8a45be
gopkg.in/fatih/pool.v2 6e328e67893eb46323ad06f0e92cb9536babbabc
gopkg.in/gorethink/gorethink.v3 7ab832f7b65573104a555d84a27992ae9ea1f659
gopkg.in/mgo.v2 3f83fa5005286a7fe593b055f0d7771a7dce4655
gopkg.in/olivere/elastic.v5 ee3ebceab960cf68ab9a89ee6d78c031ef5b4a4e
gopkg.in/yaml.v2 4c78c975fe7c825c6d1466c42be594d1d6f3aba6
11 changes: 11 additions & 0 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,17 @@
# ## rethinkdb://10.10.3.33:18832,
# ## 10.0.0.1:10000, etc.
# servers = ["127.0.0.1:28015"]
# ##
# ## If you use actual rethinkdb of > 2.3.0 with username/password authorization,
# ## protocol have to be named "rethinkdb2" - it will use 1_0 H.
# servers = ["rethinkdb2://username:password@127.0.0.1:28015"]
# ##
# ## If you use older versions of rethinkdb (<2.2) with auth_key, protocol
# ## have to be named "rethinkdb".
# servers = ["rethinkdb://username:auth_key@127.0.0.1:28015"]





# # Read metrics one or many Riak servers
Expand Down
20 changes: 19 additions & 1 deletion plugins/inputs/rethinkdb/rethinkdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"

"gopkg.in/dancannon/gorethink.v1"
"gopkg.in/gorethink/gorethink.v3"
)

type RethinkDB struct {
Expand All @@ -22,6 +22,14 @@ var sampleConfig = `
## rethinkdb://10.10.3.33:18832,
## 10.0.0.1:10000, etc.
servers = ["127.0.0.1:28015"]
##
## If you use actual rethinkdb of > 2.3.0 with username/password authorization,
## protocol have to be named "rethinkdb2" - it will use 1_0 H.
# servers = ["rethinkdb2://username:password@127.0.0.1:28015"]
##
## If you use older versions of rethinkdb (<2.2) with auth_key, protocol
## have to be named "rethinkdb".
# servers = ["rethinkdb://username:auth_key@127.0.0.1:28015"]
`

func (r *RethinkDB) SampleConfig() string {
Expand Down Expand Up @@ -75,8 +83,18 @@ func (r *RethinkDB) gatherServer(server *Server, acc telegraf.Accumulator) error
pwd, set := server.Url.User.Password()
if set && pwd != "" {
connectOpts.AuthKey = pwd
connectOpts.HandshakeVersion = gorethink.HandshakeV0_4
}
}
if server.Url.Scheme == "rethinkdb2" && server.Url.User != nil {
pwd, set := server.Url.User.Password()
if set && pwd != "" {
connectOpts.Username = server.Url.User.Username()
connectOpts.Password = pwd
connectOpts.HandshakeVersion = gorethink.HandshakeV1_0
}
}

server.session, err = gorethink.Connect(connectOpts)
if err != nil {
return fmt.Errorf("Unable to connect to RethinkDB, %s\n", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/rethinkdb/rethinkdb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/influxdata/telegraf"

"gopkg.in/dancannon/gorethink.v1"
"gopkg.in/gorethink/gorethink.v3"
)

type Server struct {
Expand Down
30 changes: 22 additions & 8 deletions plugins/inputs/rethinkdb/rethinkdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"testing"
"time"

"gopkg.in/dancannon/gorethink.v1"
"gopkg.in/gorethink/gorethink.v3"
)

var connect_url, authKey string
var connect_url, authKey, username, password string
var server *Server

func init() {
Expand All @@ -22,17 +22,31 @@ func init() {
connect_url = "127.0.0.1:28015"
}
authKey = os.Getenv("RETHINKDB_AUTHKEY")

username = os.Getenv("RETHINKDB_USERNAME")
password = os.Getenv("RETHINKDB_PASSWORD")
}

func testSetup(m *testing.M) {
var err error
server = &Server{Url: &url.URL{Host: connect_url}}
server.session, _ = gorethink.Connect(gorethink.ConnectOpts{
Address: server.Url.Host,
AuthKey: authKey,
DiscoverHosts: false,
})

if authKey {
server.session, _ = gorethink.Connect(gorethink.ConnectOpts{
Address: server.Url.Host,
AuthKey: authKey,
HandshakeVersion: gorethink.HandshakeV0_4,
DiscoverHosts: false,
})
} else {
server.session, _ = gorethink.Connect(gorethink.ConnectOpts{
Address: server.Url.Host,
Username: username,
Password: password,
HandshakeVersion: gorethink.HandshakeV1_0,
DiscoverHosts: false,
})
}

if err != nil {
log.Fatalln(err.Error())
}
Expand Down

0 comments on commit ab876bb

Please sign in to comment.