mongodb nagios plugin

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

mongodb nagios plugin

Post by elade »

Hi,

I'm using MongodDB version 3.6.3 in my system and i want to monitor it.
I saw in the forum that the Mongodb plugin is not support this version because the Auto Mechanism was changed to SCRAM-SHA-1 only.
Do you know of any other way to monitor MongoDB in Nagios XI?

Thanks for the help!
kyang

Re: mongodb nagios plugin

Post by kyang »

Hello,

Have you tried using the MongoDB wizards in Nagios XI?

https://assets.nagios.com/downloads/nag ... ios-XI.pdf
https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Please post any conflicts/errors you are having when using MongoDB 3.6.3 with our wizards.

UPDATE:


I would like to mention that, I tested both MongoDB wizards on my MongoDB 3.6.4. SCRAM-SHA-1 authentication worked perfectly fine for me. All checks came back OK.

What version of pymongo are you running?

I'm using 3.4.0 on my XI server, and 3.6.1 on my MongoDB server.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: mongodb nagios plugin

Post by elade »

Hi kyang,

Thanks for you reply.
I am using Nagios XI Version : 5.4.2 and MongoDB version v3.6.3.

I used the wizards but got auth failed message.
With the same parameters I connected successfully to MongoDB shell.

I am using pymongo==3.6.1
kyang

Re: mongodb nagios plugin

Post by kyang »

Did you set your bindIP?

I'm assuming you followed every instruction in the documentation for the MongoDB wizards?

Both wizards returned that error? I would double check the credentials.

Could you provide me with the command you used to connect to the MongoDB shell? (You can scrub out the credentials.)
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: mongodb nagios plugin

Post by elade »

Hi kyang,

BindIp is 0.0.0.0.

Yes i followed all the steps in the documentation for the MongoDB wizards.

The command is:
mongo -port 12345 -u user -p pass --authenticationDatabase DB
kyang

Re: mongodb nagios plugin

Post by kyang »

Ah that's probably why,

You currently have bindIP set to listen for local only.

I set my bindIP to the IP address of my mongoDB server and it works.

Make sure to restart the mongod service after editing the mongod.conf

Code: Select all

/etc/mongod.conf

Code: Select all

service mongod restart
Try that out and let me know.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: mongodb nagios plugin

Post by elade »

Hi kyang,

Sorry for the delay.

I added the mongoDB server IP to bindIP but then I can't connect to the shell with the same user.
I aslo run the mongodb script from nagios with all the argumets and I get the following error:

./check_mongodb.py -H X.X.X.X -A database_size -P XXX -W 00 -C 000-u U -p P -d DB
CRITICAL - General MongoDB Error: command SON([('authenticate', 1), ('user', u'U'), ('nonce', u''), ('key', u'')]) failed: auth failed.

Any ideas?
kyang

Re: mongodb nagios plugin

Post by kyang »

I would say double check your credentials.

On your MongoDB server, try using the python shell to authenticate. (Make sure to use your IP of mongoDB and the correct username & password within the single quotes)

Code: Select all

python

>>>from pymongo import MongoClient

>>>client = MongoClient('bindIPofMongoDB')

>>>client.admin.authenticate('myUserName', 'password', mechanism='SCRAM-SHA-1')
After this, it should either display True or throw an error.

Also, go into mongodb and send the me the list of users so I can see the roles.
Also send me what you have for db.getUsers()

Code: Select all

> use <yourDB>
> db.getUsers()
Please post your output.
elade
Posts: 144
Joined: Wed Mar 28, 2018 6:23 am

Re: mongodb nagios plugin

Post by elade »

Hi kyang,

I ran the python shell commands which you wrote and go the follwing errors:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mongouser/.local/lib/python2.7/site-packages/pymongo/database.py", line 1167, in authenticate
    connect=True)
  File "/home/mongouser/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 583, in _cache_credentials
    writable_preferred_server_selector)
  File "/home/mongouser/.local/lib/python2.7/site-packages/pymongo/topology.py", line 224, in select_server
    address))
  File "/home/mongouser/.local/lib/python2.7/site-packages/pymongo/topology.py", line 183, in select_servers
    selector, server_timeout, address)
  File "/home/mongouser/.local/lib/python2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: X.X.X.X:YYY: [Errno 111] Connection refused
db.getUsers():

Code: Select all

db.getUsers()
[
        {
                "_id" : "Test.nagios",
                "user" : "nagios",
                "db" : "Test",
                "roles" : [
                        {
                                "role" : "backup",
                                "db" : "Test"
                        }
                ]
        }
                ]
]
I have another user same info but the role is diffrent.
Instand of "backup" in the other user it shows "raedWrite"

Do you think that is the problem?
kyang

Re: mongodb nagios plugin

Post by kyang »

Hello,

Thanks for the output!

Yes, looking back at the documentation.
You are required to have a user in the admin database that has the role of clusterAdmin.
This role is required by MongoDB to access statistics on the MongoDB server. You can reference the link below for information about creating users for a MongoDB:
https://assets.nagios.com/downloads/nag ... 1521646370
https://assets.nagios.com/downloads/nag ... 1521646370

The role needs to be set to clusterAdmin.

Code: Select all

MongoDB Enterprise > db.getUsers()
[
        {
                "_id" : "admin.myUserAdmin",
                "user" : "myUserAdmin",
                "db" : "admin",
                "roles" : [
                        {
                                "role" : "userAdminAnyDatabase",
                                "db" : "admin"
                        }
                ]
        }
]
That's what I have, and thats the username I am using when doing my checks from XI.

Code: Select all

[root@localhost libexec]# ./check_mongodb.py -H 192.168.3.160 -u myUserAdmin -p abc123 -d admin
OK - Connection took 0 seconds
Locked