Module: check_mk
Branch: master
Commit: 928cf173f2ddd60fd641561583d3640c76f6a9db
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=928cf173f2ddd6…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Apr 4 09:11:40 2019 +0200
mk_mongodb: avoid deprecated method
Change-Id: I2385525a912498f368a49fdc554e79d7ddf0d8af
---
agents/plugins/mk_mongodb | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/agents/plugins/mk_mongodb b/agents/plugins/mk_mongodb
index 43351de..248cdd6 100755
--- a/agents/plugins/mk_mongodb
+++ b/agents/plugins/mk_mongodb
@@ -93,14 +93,18 @@ def potentially_piggybacked_sections(con, server_status, repl_info):
sys.stdout.write("<<<mongodb_connections>>>\n")
sys.stdout.write("%s\n" % "\n".join("%s %s" % x for x
in server_status["connections"].items()))
- databases = {x: {} for x in con.database_names()}
-
- for name in databases.keys():
- databases[name]["collections"] = con[name].collection_names()
- databases[name]["stats"] = con[name].command("dbstats")
+ try:
+ databases = {x: {} for x in con.list_database_names()}
+ except AttributeError: # pymongo < 3.6
+ databases = {x: {} for x in con.database_names()}
+
+ for name in databases:
+ database = con[name]
+ databases[name]["collections"] = database.collection_names()
+ databases[name]["stats"] = database.command("dbstats")
databases[name]["collstats"] = {}
for collection in databases[name]["collections"]:
- databases[name]["collstats"][collection] =
con[name].command("collstats", collection)
+ databases[name]["collstats"][collection] =
database.command("collstats", collection)
sys.stdout.write("<<<mongodb_chunks>>>\n")
col = con.config.chunks