From 94cc2f88053089392daac567218a0e4632e6477c Mon Sep 17 00:00:00 2001 From: Conor Branagan Date: Thu, 5 Sep 2013 21:39:53 +0000 Subject: [PATCH] Fetch the Mongo database name from the URI. --- checks.d/mongo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/checks.d/mongo.py b/checks.d/mongo.py index ba6d450f16..7c5c511fbd 100644 --- a/checks.d/mongo.py +++ b/checks.d/mongo.py @@ -126,6 +126,11 @@ def check(self, instance): parsed = {} username = parsed.get('username') password = parsed.get('password') + db_name = parsed.get('database') + + if not db_name: + self.log.info('No MongoDB database found in URI. Defaulting to admin.') + db_name = 'admin' do_auth = True if username is None or password is None: @@ -133,7 +138,7 @@ def check(self, instance): do_auth = False conn = Connection(instance['server'], network_timeout=DEFAULT_TIMEOUT) - db = conn['admin'] + db = conn[db_name] if do_auth: if not db.authenticate(username, password): self.log.error("Mongo: cannot connect with config %s" % instance['server'])