mzupan/nagios-plugin-mongodb — pull request #24 by organicveggie (2012-02-06 20:39:20+00:00)
Title: Fixed replication_lag check & slave_ok deprecation warning

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.