Mk_mongodb and mongodb_connections plugins not being discovered

Hello

I am running check_mk raw version 1.6.0 in a Debian 10 environment.
I wish to perform mongoDB checks on a server running Debian 10 as well and I copied both mk_mongodb and mongodb_connections from the builtin plugins to the server’s /usr/lib/check_mk_agent/plugins directory.

The server has python and pymongo installed.

Whenever I try to do a service discovery in the GUI as well as on the command line it doesn’t find any of the plugins.

I am running mk_apt plugin on the same server and this works perfectly.

Hoping to find some help and/or insights here
Thanks in advance.

Does the plugin work when you run it manually from the command line ?

Assuming you mean running the script on the remote server, it gives me the following output:

/usr/lib/check_mk_agent/plugins# python mk_mongodb
Traceback (most recent call last):
File “mk_mongodb”, line 253, in
sys.exit(main())
File “mk_mongodb”, line 223, in main
server_status = client.admin.command(“serverStatus”)
File “/usr/local/lib/python2.7/dist-packages/pymongo/database.py”, line 740, in command
codec_options, session=session, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/pymongo/database.py”, line 637, in _command
client=self.__client)
File “/usr/local/lib/python2.7/dist-packages/pymongo/pool.py”, line 694, in command
exhaust_allowed=exhaust_allowed)
File “/usr/local/lib/python2.7/dist-packages/pymongo/network.py”, line 161, in command
parse_write_concern_error=parse_write_concern_error)
File “/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py”, line 160, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: command serverStatus requires authentication, full error: {u’codeName’: u’Unauthorized’, u’code’: 13, u’ok’: 0.0, u’errmsg’: u’command serverStatus requires authentication’}

/usr/lib/check_mk_agent/plugins# python mongodb_connections
Traceback (most recent call last):
File “mongodb_connections”, line 33, in
‘levels_perc’: (80.0, 90.0), # Levels at 80%/90% of maximum
NameError: name ‘factory_settings’ is not defined

Which one are you using? There are two:
mk_mongodb.py --Python3
mk_mongodb_2.py --Python2

1.6 has only one mk_mongodb for Python 2.

This is no plugin this is the check from CMK itself. You can remove it from the host you want to monitor.

Your MongoDB cannot be connected without authentication.

We have the same problem. We cannot monitor the Mongo DB because of the missing authentication.
What does that mean? Or in other words, how we are able to use the mk_mongodb plugin, while authentication is enabled on the MongoDB.
For other DB plugins like MSSQL or Oracle we are able to define the authentification in a configuration file, but how is this done for the MongoDB plugin?

Thanks for any hints

This helped me set it up:

Throw it into a translator if you don’t speak german.
Basically you need to create a user and give them some roles in mongodb and then edit the mk_mongodb file to use that user’s credentials to authenticate.

Thanks for the reply.
I already have a user with the roles I need … just need to know how to add the credential information for the agent bakery.
As I understand your post I have to add the authentification part to the mk_mongodb file.
So there is no build in solution and I have to costumize the mk_mongodb file.
Sorry I have no idea how to do that, I don’t know pyton or whatever language I need.

by the way we are using 1.6p21 enterprise edition

Yes at the moment you cannot use the agent bakery to deploy this plugin with credentials.
But what you can do is build an agent for this host without the plugin and deploy this plugin manually.
The change you need to do inside the plugin don’t need programming know how.

Original file line 219

def main():
    client = pymongo.MongoClient(read_preference=pymongo.ReadPreference.SECONDARY)
    try:

Modified version

def main():
    client = pymongo.MongoClient(‘mongodb.example.com’, username=‘monitoring’, password=“verysecret”, authSource=‘admin’, authMechanism=‘SCRAM-SHA-1’)
    try:

For the “mongodb.example.com” you need to select your database host.

3 Likes

Thanks for your answer.
That obviously sounds easy, but now I just get another error

Traceback (most recent call last):
File “./mk_mongodb”, line 253, in
sys.exit(main())
File “./mk_mongodb”, line 220, in main
client = pymongo.MongoClient(“mymongohost.domain.com”, username=“myuser”, password=“mypassword”, authSource=“admin”, authMechanism=“SCRAM-SHA-1”)
File “/usr/lib64/python2.7/site-packages/pymongo/mongo_client.py”, line 258, in init
option, value = common.validate(option, value)
File “/usr/lib64/python2.7/site-packages/pymongo/common.py”, line 243, in validate
value = validator(option, value)
File “/usr/lib64/python2.7/site-packages/pymongo/common.py”, line 39, in raise_config_error
raise ConfigurationError(“Unknown option %s” % (key,))
pymongo.errors.ConfigurationError: Unknown option username

It depends on the pymongo version i think.
What version do you use on your system?

On the webpage from pymongo you can find some examples.
https://pymongo.readthedocs.io/en/stable/examples/authentication.html

Thanks for your response.

I just checked the version of pymongo on the DB server and it’s version 2.5.2.
Seems a quite old version.
The mk_mongodb plugin sits an the mongo db server, so it uses the pymongo module of the mongo db server. Do we need the pymongo module on the checkmk server itself also?
Or do we need just to update the version of the pymongo on the db server?

Hi @michael.blaser

If you need to use a newer pymongo version, I believe you need to upgrade it wherever you’re running the check script.

HTH,
Thomas

Thank you for your respnse.

We are trying to update the pymongo Mudule and test then again.

Simple and Powerfull

Thanks a lot

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.