Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring replication_lag with authorization gives a generic error #169

Open
mvdwalle opened this issue Jul 27, 2015 · 8 comments
Open

Comments

@mvdwalle
Copy link

I am monitoring my mongodb replicaset with this plugin and encountered the following error:
CRITICAL - General MongoDB Error: can't set attribute

I am running the command as follows:
/usr/lib/nagios/plugins/check_mongodb -A replication_lag -W 5 -C 10 -M 3 -u {user} --pass={pass}

I have tested the plugin on a set without authentication and everything works fine.

@mvdwalle
Copy link
Author

I managed to trace this down to def set_read_preference(db) it tries to set the read preference however this: http://api.mongodb.org/python/current/api/pymongo/database.html#pymongo.database.Database.read_preference

states that the property is now read only.

@hdeheer
Copy link
Contributor

hdeheer commented Aug 5, 2015

@mvdwalle which version of PyMongo are you using?
I'm interested to see if my pull request (#161) will fix your issue if you're using PyMongo > 3.x
See also: hdeheer@65a9af1

@mvdwalle
Copy link
Author

mvdwalle commented Aug 6, 2015

I am using version 3.0.3, your pull request unfortunatly does not solve the problem. In pymongo 3+ the read preference cannot be changed on the connection level any more and needs to be sent with the command:

set_read_preference(con.admin) cannot be used anymore.

@hdeheer
Copy link
Contributor

hdeheer commented Aug 6, 2015

Ok, I will have a look. Maybe can drop the whole function as setting read_preference/slave_okay is already done in mongo_connect()

@BoemmLA
Copy link

BoemmLA commented Aug 6, 2015

That would be great, I hit the same problem and thought I used the wrong python version or so ...
But if it can be fixed in the monitoring script it would be great!

@mvdwalle
Copy link
Author

mvdwalle commented Aug 6, 2015

Setting read preference might be needed for some checks. But you can do it on query time. I did that for this specific check:

rs_status = con.admin.command("replSetGetStatus", read_preference=pymongo.ReadPreference.SECONDARY)

@err0rs
Copy link

err0rs commented Aug 17, 2015

for the time being i am downgrading to "pip install pymongo==2.8"

@warrenpnz
Copy link
Contributor

Your problem is that the read prefernce function is trying to set a read only variable. Change it to this:

def set_read_preference(db):
    if pymongo.version >= "2.2":
        pymongo.read_preferences.Secondary
    else:
        db.read_preference = pymongo.ReadPreference.SECONDARY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants