Open IdahoPL opened 8 years ago
That's odd I have continuous integration running on this and testing this plugin against a live MongoDB instance and I can see it built yesterday with version 1.0.2 and the plugin ran fine, you can see the output here:
https://travis-ci.org/harisekhon/nagios-plugins/jobs/87368827
I see in that log that you are running ./check_mongodb_write.pl --help. I agree that it is working with MongoDB 1.0.2. But try to connect to mongodb server using login and password, you'll then see the problem with 1.0.2.
Documentation clearly says that "authenticate" method was removed: http://search.cpan.org/~mongodb/MongoDB-v1.0.0/lib/MongoDB/Upgrading.pod
That's later on, see line 2134 that was a run against a MongoDB which succeeded:
OK: document written in 0.1864 secs, read in 0.0053 secs, deleted in 0.0288 secs | write_time=0.1864s;;; read_time=0.0053s;;; delete_time=0.0288s;;;
I will look in to updating this plugin however.
Ah I think I know why this may be, the CI is using unauthenticated Mongo and your issue is only occuring when calling authenticate.
@IdahoPL
I've just updated this check and the underlying libraries for the API changes introduced in the 1.x Mongo driver.
I've also added functional tests for both authenticated and unauthenticated mongo systems so this will be checked automatically in future.
Try a make update
- this should solve it for you.
Thanks
Hari
I'm having problems with auth after upgrading perl MongoDB to 1.2.1.
On Nagios host:
Already up-to-date.
On Mongo host: $ mongo admin -u idaho -p MongoDB shell version: 2.4.6 Enter password: connecting to: admin
use nagios switched to db nagios db.addUser( { user: "foo", pwd: "bar", roles: [ "readWrite", "dbAdmin" ] }) { "user" : "foo", "pwd" : "3563025c1e89c7ad43fb63fcbcf1c3c6", "roles" : [ "readWrite", "dbAdmin" ], "_id" : ObjectId("56c3b7ac4ef79619ed85b0da") }
Let's test from Mongo host: $ mongo nagios -u foo -p bar MongoDB shell version: 2.4.6 connecting to: nagios
show collections check_mongodb_write system.indexes system.users
Let's test from Nagios host:
CRITICAL: failed to insert document in to database 'nagios' collection 'check_mongodb_write': MongoDB::AuthError: Authentication to x.x.x.x:27017 failed: MongoDB::DatabaseError: auth fails
If you look at tests/test_mongodb.sh
you can see how the authentication test is done... I'm basically creating a user like so:
db.createUser({"user":"$MONGODB_USERNAME", "pwd":"$MONGODB_PASSWORD", "roles":[{role:"root", db:"admin"}]})
which you can see here: https://github.com/HariSekhon/nagios-plugins/blob/master/tests/test_mongodb.sh#L94
This might be a permissions issue in Mongo as I'm using a more privileged account for the test which works.
However, re-reading your last comment actually given this works from mongo shell but not in the plugin I'll have to investigate further this weekend - does it work if you specify a more privileged account?
Also did you do a make update
to pull in the underlying library changes where the authentication handling has changed for Mongo 1.x driver?
After upgrade perl MongoDB from 0.708.4.0 to 1.0.2 im getting:
CRITICAL: failed to authenticate: Can't locate object method "authenticate" via package "MongoDB::MongoClient" at ./nagios-plugins/check_mongodb_write.pl line 173.
It's caused by MongoDB-v1.0.0+ deprecation of authenticate method:
http://search.cpan.org/~mongodb/MongoDB-v1.0.0/lib/MongoDB/Upgrading.pod says:
The old authenticate method in MongoDB::MongoClient has been removed.
Here is the new way: https://www.mongodb.com/blog/post/introducing-the-1-0-perl-driver
WRONG WAY IS FATAL
$client = MongoDB->connect() $client->authenticate("foo", "username", "sekret");
RIGHT WAY
$client = MongoDB->connect("mongodb://username:sekret@localhost/foo");