Add support for RethinkDB 1.0 handshake protocol (#2963)

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
This commit is contained in:
vodolaz095
2017-06-27 00:29:48 +03:00
committed by Daniel Nelson
parent 22fc130e97
commit 1fdbfa4719
5 changed files with 54 additions and 11 deletions

View File

@@ -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 {
@@ -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 {
@@ -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())

View File

@@ -11,7 +11,7 @@ import (
"github.com/influxdata/telegraf"
"gopkg.in/dancannon/gorethink.v1"
"gopkg.in/gorethink/gorethink.v3"
)
type Server struct {

View File

@@ -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() {
@@ -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())
}