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:
parent
f070f1460a
commit
ab876bb525
2
Godeps
2
Godeps
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
"github.com/influxdata/telegraf"
|
||||
|
||||
"gopkg.in/dancannon/gorethink.v1"
|
||||
"gopkg.in/gorethink/gorethink.v3"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
|
|
@ -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}}
|
||||
|
||||
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())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue