@cryptotaxi247 / netdata-1 / commits / 32b8993f3

NEW: authdb option for MongoDB collector (#5707)

* 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

Andrey Galkin committed Mar 29, 2019 at 13:28 UTC 32b8993f3c608072ecee041677f3c6ce74a9cd98
3 files changed +13 -1
collectors/python.d.plugin/mongodb/README.md
+1
@@ -156,6 +156,7 @@ Sample:
156 ```yaml
157 local:
158 name : 'local'
159 + authdb: 'admin'
160 host : '127.0.0.1'
161 port : 27017
162 user : 'netdata'
collectors/python.d.plugin/mongodb/mongodb.chart.py
+2 -1
@@ -424,6 +424,7 @@ class Service(SimpleService):
424 SimpleService.__init__(self, configuration=configuration, name=name)
425 self.order = ORDER[:]
426 self.definitions = deepcopy(CHARTS)
427 + self.authdb = self.configuration.get('authdb', 'admin')
428 self.user = self.configuration.get('user')
429 self.password = self.configuration.get('pass')
430 self.host = self.configuration.get('host', '127.0.0.1')
@@ -707,7 +708,7 @@ class Service(SimpleService):
708 try:
709 connection = MongoClient(**conn_vars)
710 if self.user and self.password:
710 - connection.admin.authenticate(name=self.user, password=self.password)
711 + getattr(connection, self.authdb).authenticate(name=self.user, password=self.password)
712 # elif self.user:
713 # connection.admin.authenticate(name=self.user, mechanism='MONGODB-X509')
714 server_status = connection.admin.command('serverStatus')
collectors/python.d.plugin/mongodb/mongodb.conf
+10
@@ -66,6 +66,8 @@
66 #
67 # in all cases, the following can also be set:
68 #
69 +# authdb: 'dbname' # database to authenticate the user against,
70 +# # defaults to "admin".
71 # user: 'username' # the mongodb username to use
72 # pass: 'password' # the mongodb password to use
73 #
@@ -80,3 +82,11 @@ local:
82 name : 'local'
83 host : '127.0.0.1'
84 port : 27017
85 +
86 +# authsample:
87 +# name : 'secure'
88 +# host : 'mongodb.example.com'
89 +# port : 27017
90 +# authdb : 'admin'
91 +# user : 'monitor'
92 +# password : 'supersecret'