Page 1 of 2

check_mongodb.py errors

Posted: Mon May 18, 2015 11:49 am
by monitoreo1
I need to monitor resources MongoDB .
I may indicate how to resolve the following errors in nagios:

File "/usr/local/nagios/libexec/check_mongodb.py", line 1372, in <module>
sys.exit(main(sys.argv[1:]))
File "/usr/local/nagios/libexec/check_mongodb.py", line 196, in main
err, con = mongo_connect(host, port, ssl, user, passwd, replicaset)
File "/usr/local/nagios/libexec/check_mongodb.py", line 294, in mongo_connect
return exit_with_general_critical(e), None
File "/usr/local/nagios/libexec/check_mongodb.py", line 310, in exit_with_general_critical
if e.strip() == "not master":
AttributeError: 'ConnectionFailure' object has no attribute 'strip'


We are using:
Nagios XI Version : 2014R2.6
x86_64
Red Hat Enterprise Linux Server release 7.0 (Maipo)
Gnome is not installed

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 12:28 pm
by jdalrymple
Instead of me trying to chase your python script around the Internet please post a copy here.

Just as a precurser, it's likely that e is supposed to be set as a string earlier in the script but that's not happening for one reason or another. I can help debug if I can see the script.

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 12:33 pm
by jolson
What happens if you run the plugin from the CLI with the 'help' option?

Code: Select all

cd /usr/local/nagios/libexec
./check_mongodb.py -h
Is there any problem there? What if you pass it some variables to monitor your mongodb server? Use the help page to setup your check properly, below is just an example.

Code: Select all

./check_mongodb.py -H x.x.x.x -P port -u USER -p PASSWD

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 12:42 pm
by monitoreo1
I am running the command as follows:

# /usr/local/nagios/libexec/check_mongodb.py -H 150.100.38.228

# /usr/local/nagios/libexec/check_mongodb.py -H 150.100.38.228
Traceback (most recent call last):
File "/usr/local/nagios/libexec/check_mongodb.py", line 1372, in <module>
sys.exit(main(sys.argv[1:]))
File "/usr/local/nagios/libexec/check_mongodb.py", line 196, in main
err, con = mongo_connect(host, port, ssl, user, passwd, replicaset)
File "/usr/local/nagios/libexec/check_mongodb.py", line 294, in mongo_connect
return exit_with_general_critical(e), None
File "/usr/local/nagios/libexec/check_mongodb.py", line 310, in exit_with_general_critical
if e.strip() == "not master":
AttributeError: 'ConnectionFailure' object has no attribute 'strip'


I share the script in this link:

https://www.dropbox.com/s/e6msnz41n4stm ... db.py?dl=0

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 12:48 pm
by monitoreo1
I am relying on the following documentation

Monitoring-MongoDB-Server-With-Nagios-XI

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

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 12:59 pm
by jolson
Your script matches mine, except the beginning of your script includes:

Code: Select all

> # /usr/local/nagios/libexec/check_mongodb.py -H 150.100.38.228
> Traceback (most recent call last):
>   File "/usr/local/nagios/libexec/check_mongodb.py", line 1372, in <module>
>     sys.exit(main(sys.argv[1:]))
>   File "/usr/local/nagios/libexec/check_mongodb.py", line 196, in main
>     err, con = mongo_connect(host, port, ssl, user, passwd, replicaset)
>   File "/usr/local/nagios/libexec/check_mongodb.py", line 294, in mongo_connect
>     return exit_with_general_critical(e), None
>   File "/usr/local/nagios/libexec/check_mongodb.py", line 310, in exit_with_general_critical
>     if e.strip() == "not master":
> AttributeError: 'ConnectionFailure' object has no attribute 'strip'
I am hoping that this was a simple pasting error.

It looks like check_mongodb will fail with syntax errors if it doesn't complete properly. Can you try specifying a username/password along with a database?

Code: Select all

/usr/local/nagios/libexec/check_mongodb.py -H x.x.x.x -u USER -p PASSWD -d DATABASE
If you run the help command, do you get proper output?

Code: Select all

/usr/local/nagios/libexec/check_mongodb.py -h

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 1:18 pm
by monitoreo1
The statement is executed successfully:

/usr/local/nagios/libexec/check_mongodb.py -h

The lines are added to the script only as supplementary information
(No output on stdout) stderr: Traceback (most recent call last):
File "/usr/local/nagios/libexec/check_mongodb.py", line 1372, in <module>
sys.exit(main(sys.argv[1:]))
File "/usr/local/nagios/libexec/check_mongodb.py", line 196, in main
err, con = mongo_connect(host, port, ssl, user, passwd, replicaset)
File "/usr/local/nagios/libexec/check_mongodb.py", line 294, in mongo_connect
return exit_with_general_critical(e), None
File "/usr/local/nagios/libexec/check_mongodb.py", line 310, in exit_with_general_critical
if e.strip() == "not master":
AttributeError: 'ConnectionFailure' object has no attribute 'strip'

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 1:26 pm
by monitoreo1
I have a question , you must install the agent nrpe my nagios server, the plugin only able to monitor MongoDB resources

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 1:36 pm
by jolson
The check_mongodb.py plugin is used for checking on the status of the service mongodb only - it can be used to check on mongodb-specific things like replication lag and queries. If you don't need to monitor mongodb in that granular of a sense, you can certainly use NRPE to monitor the server in question instead. You can also use a combination of the two plugins (check_nrpe and check_mongodb.py).

Your mongodb plugin is not broken - mine will throw the same errors if the mongodb service is not running on the remote machine, or if Nagios doesn't have access to it:

Code: Select all

[root@localhost libexec]# ./check_mongodb.py -H 192.168.1.1 -u "" -p "" -d admin
Traceback (most recent call last):
  File "./check_mongodb.py", line 1372, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./check_mongodb.py", line 196, in main
    err, con = mongo_connect(host, port, ssl, user, passwd, replicaset)
  File "./check_mongodb.py", line 294, in mongo_connect
    return exit_with_general_critical(e), None
  File "./check_mongodb.py", line 310, in exit_with_general_critical
    if e.strip() == "not master":
AttributeError: 'ConnectionFailure' object has no attribute 'strip'
However if I start the service:

Code: Select all

[root@localhost libexec]# ./check_mongodb.py -H 192.168.4.109 -u "" -p ""
OK - Connection took 0 seconds
Everything looks good.

Does that all make sense?

Re: check_mongodb.py errors

Posted: Mon May 18, 2015 3:25 pm
by monitoreo1
I share the image on the nagios screen :

https://www.dropbox.com/s/m5j4p9q6s2exz ... B.PNG?dl=0


and

https://www.dropbox.com/s/5lls6ogstf2sa ... 2.PNG?dl=0

When executing the instruction

./check_mongodb.py -H HOSTIP -u "" -p ""

The output is:

(No output on stdout) stderr: Traceback (most recent call last):
File "/usr/local/nagios/libexec/check_mongodb.py", line 1372, in <module>
sys.exit(main(sys.argv[1:]))
File "/usr/local/nagios/libexec/check_mongodb.py", line 196, in main
err, con = mongo_connect(host, port, ssl, user, passwd, replicaset)
File "/usr/local/nagios/libexec/check_mongodb.py", line 294, in mongo_connect
return exit_with_general_critical(e), None
File "/usr/local/nagios/libexec/check_mongodb.py", line 310, in exit_with_general_critical
if e.strip() == "not master":
AttributeError: 'ConnectionFailure' object has no attribute 'strip'