Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #28 from cangove/master

Support for pymongo >= 1.9
  • Loading branch information...
commit c6899d78c57c79dcb7234bad3c16554fd4161327 2 parents 01a3aa9 + 647aaea
@mzupan mzupan authored
Showing with 15 additions and 9 deletions.
  1. +15 −9 check_mongodb.py
View
24 check_mongodb.py
@@ -29,11 +29,17 @@
try:
import pymongo
- import pymongo.son
except ImportError, e:
print e
sys.exit(2)
+# As of pymongo v 1.9 the SON API is part of the BSON package, therefore attempt
+# to import from there and fall back to pymongo in cases of older pymongo
+if pymongo.version >= "1.9":
+ import bson.son as son
+else:
+ import pymongo.son as son
+
#
# thanks to http://stackoverflow.com/a/1229667/72987
#
@@ -163,7 +169,7 @@ def check_connections(con, warning, critical, perf_data):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('serverStatus', 1), ('repl', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('serverStatus', 1), ('repl', 1)]))
+ data = con.admin.command(son.SON([('serverStatus', 1), ('repl', 1)]))
current = float(data['connections']['current'])
available = float(data['connections']['available'])
@@ -249,7 +255,7 @@ def check_memory(con, warning, critical, perf_data):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('serverStatus', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('serverStatus', 1)]))
+ data = con.admin.command(son.SON([('serverStatus', 1)]))
if not data['mem']['supported']:
@@ -288,7 +294,7 @@ def check_lock(con, warning, critical, perf_data):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('serverStatus', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('serverStatus', 1)]))
+ data = con.admin.command(son.SON([('serverStatus', 1)]))
#
# calculate percentage
@@ -326,7 +332,7 @@ def check_flushing(con, warning, critical, avg, perf_data):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('serverStatus', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('serverStatus', 1)]))
+ data = con.admin.command(son.SON([('serverStatus', 1)]))
if avg:
flush_time = float(data['backgroundFlushing']['average_ms'])
@@ -361,7 +367,7 @@ def index_miss_ratio(con, warning, critical, perf_data):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('serverStatus', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('serverStatus', 1)]))
+ data = con.admin.command(son.SON([('serverStatus', 1)]))
try:
miss_ratio = float(data['indexCounters']['btree']['missRatio'])
@@ -398,7 +404,7 @@ def check_replset_state(con):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('replSetGetStatus', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('replSetGetStatus', 1)]))
+ data = con.admin.command(son.SON([('replSetGetStatus', 1)]))
state = int(data['myState'])
@@ -439,7 +445,7 @@ def check_databases(con, warning, critical):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('listDatabases', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('listDatabases', 1)]))
+ data = con.admin.command(son.SON([('listDatabases', 1)]))
count = len(data['databases'])
@@ -462,7 +468,7 @@ def check_collections(con, warning, critical):
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('listDatabases', 1)]))
except:
- data = con.admin.command(pymongo.son.SON([('listDatabases', 1)]))
+ data = con.admin.command(son.SON([('listDatabases', 1)]))
count = 0
for db in data['databases']:
Please sign in to comment.
Something went wrong with that request. Please try again.