0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-17 19:22:40 +00:00

NEW: authdb option for MongoDB collector ()

* NEW: authdb option for MongoDB collector

* Extended mongodb.conf example with authdb option

* Commented out secure example in mongodb.conf

* FIXED: mongodb changes to be compatible with pre-Py2.4
This commit is contained in:
Andrey Galkin 2019-03-29 13:28:59 +02:00 committed by Chris Akritidis
parent 1e682dc59c
commit 32b8993f3c
3 changed files with 13 additions and 1 deletions
collectors/python.d.plugin/mongodb

View file

@ -156,6 +156,7 @@ Sample:
```yaml
local:
name : 'local'
authdb: 'admin'
host : '127.0.0.1'
port : 27017
user : 'netdata'

View file

@ -424,6 +424,7 @@ class Service(SimpleService):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER[:]
self.definitions = deepcopy(CHARTS)
self.authdb = self.configuration.get('authdb', 'admin')
self.user = self.configuration.get('user')
self.password = self.configuration.get('pass')
self.host = self.configuration.get('host', '127.0.0.1')
@ -707,7 +708,7 @@ class Service(SimpleService):
try:
connection = MongoClient(**conn_vars)
if self.user and self.password:
connection.admin.authenticate(name=self.user, password=self.password)
getattr(connection, self.authdb).authenticate(name=self.user, password=self.password)
# elif self.user:
# connection.admin.authenticate(name=self.user, mechanism='MONGODB-X509')
server_status = connection.admin.command('serverStatus')

View file

@ -66,6 +66,8 @@
#
# in all cases, the following can also be set:
#
# authdb: 'dbname' # database to authenticate the user against,
# # defaults to "admin".
# user: 'username' # the mongodb username to use
# pass: 'password' # the mongodb password to use
#
@ -80,3 +82,11 @@ local:
name : 'local'
host : '127.0.0.1'
port : 27017
# authsample:
# name : 'secure'
# host : 'mongodb.example.com'
# port : 27017
# authdb : 'admin'
# user : 'monitor'
# password : 'supersecret'