Skip to content

Commit

Permalink
Merge pull request #195 from sharon-tickell/arbiter_support
Browse files Browse the repository at this point in the history
Use ping to verify the connection because database_names always fails on an arbiter with authentication enabled
  • Loading branch information
mzupan committed Jul 28, 2017
2 parents fe49d1e + 9fdaab8 commit 442cd45
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions check_mongodb.py
Expand Up @@ -331,6 +331,9 @@ def mongo_connect(host=None, port=None, ssl=False, user=None, passwd=None, repli
except PyMongoError:
sys.exit("Username/Password incorrect")

# Ping to check that the server is responding.
con.admin.command("ping")

except Exception, e:
if isinstance(e, pymongo.errors.AutoReconnect) and str(e).find(" is an arbiter") != -1:
# We got a pymongo AutoReconnect exception that tells us we connected to an Arbiter Server
Expand Down Expand Up @@ -810,14 +813,15 @@ def check_replset_state(con, perf_data, warning="", critical=""):

ok = range(-1, 8) # should include the range of all posiible values
try:
worst_state = -2
message = ""
try:
try:
set_read_preference(con.admin)
data = con.admin.command(pymongo.son_manipulator.SON([('replSetGetStatus', 1)]))
except:
data = con.admin.command(son.SON([('replSetGetStatus', 1)]))
members = data['members'];
message = ""
my_state = int(data['myState'])
worst_state = my_state
for member in members:
Expand All @@ -829,7 +833,7 @@ def check_replset_state(con, perf_data, warning="", critical=""):

except pymongo.errors.OperationFailure, e:
if ((e.code == None and str(e).find('failed: not running with --replSet"')) or (e.code == 76 and str(e).find('not running with --replSet"'))):
state = -1
worst_state = -1

return check_levels(worst_state, warning, critical, message, ok)
except Exception, e:
Expand Down

0 comments on commit 442cd45

Please sign in to comment.