Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions check_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,29 +821,31 @@ def check_replset_state(con, perf_data, warning="", critical=""):
except:
critical = [8, 4, -1]

ok = list(range(-1, 8)) # should include the range of all posiible values
ok = list(range(-1, 8)) # should include the range of all possible values
try:
worst_state = -2
worst_state = -1
message = ""
data = []
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']
my_state = int(data['myState'])
worst_state = my_state
for member in members:
their_state = int(member['state'])
message += " %s: %i (%s)" % (member['name'], their_state, state_text(their_state))
if state_is_worse(their_state, worst_state, warning, critical):
worst_state = their_state
message += performance_data(perf_data, [(my_state, "state")])

set_read_preference(con.admin)
data = con.admin.command("replSetGetStatus", check=False)
if(data['ok'] == 1):
members = data['members']
my_state = int(data['myState'])
worst_state = my_state
for member in members:
their_state = int(member['state'])
message += " %s: %i (%s)" % (member['name'], their_state, state_text(their_state))
if state_is_worse(their_state, worst_state, warning, critical):
worst_state = their_state
message += performance_data(perf_data, [(my_state, "state")])
else:
message += data['errmsg']

except pymongo.errors.OperationFailure as 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"'))):
worst_state = -1
worst_state = -1
message += str(e)

return check_levels(worst_state, warning, critical, message, ok)
except Exception as e:
Expand Down Expand Up @@ -873,8 +875,6 @@ def state_text(state):
return "Secondary"
elif state == 7:
return "Arbiter"
elif state == -1:
return "Not running with replSet"
else:
return "Unknown state"

Expand Down