Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixed replication_lag check & slave_ok deprecation warning #24
The previous replication lag check does not work correctly and used data ("local.slaves") that is unsupported. According to 10gen, the local.slaves "collection is not for public use and just part of the replica set internals". Specifically, the local.slaves collection will include secondary nodes that have been removed from the replica set. In addition, it didn't make a lot of sense to only have the primary report replication problems and have the secondaries report "OK", even if they were behind in replication.
The first commit replaces the old logic with a simple use of the replSetGetStatus function in MongoDB. Primaries now always report OK, since they cannot possibly be behind in replication. Secondaries report WARNING or CRITICAL if they are more than X seconds behind the primary.
The remaining commits deal with the fact that passing the "slave_ok" parameter to pymongo.Connection() is deprecated as of 2.1 and throws a warning. Since python displays the warning on standard out, Nagios reads that and believes the request has failed. The commits add support for eliminating the "slave_ok" parameter and setting db.read_preference, but only for pymongo version 2.1 and later.