While applying mongodb monitoring checks on new MongoDB servers, the following error was showing up when the database_size action (check type) was used:
root@mon:/usr/lib/nagios/plugins# ./check_mongodb.py -H 10.10.160.13 -P 30000 --all-databases -A database_size
Traceback (most recent call last):
File "./check_mongodb.py", line 1651, in <module>
sys.exit(main(sys.argv[1:]))
File "./check_mongodb.py", line 247, in main
return check_all_databases_size(con, warning, critical, perf_data)
File "./check_mongodb.py", line 927, in check_all_databases_size
all_dbs_data = con.admin.command(son.SON([('listDatabases', 1)]))
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 439, in command
uuid_subtype, compile_re, **kwargs)[0]
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line 345, in _command
msg, allowable_errors)
File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line 163, in _check_command_response
raise AutoReconnect(errmsg)
pymongo.errors.AutoReconnect: not master and slaveOk=false
I was unable to find relevant issues in the check_mongodb's Github repository, however I came across one (as of this writing) open issue stating that check_mongodb.py requires python3.
By simply executing the plugin, the script interpreter in the first line is chosen. Which is referring to env python:
root@mon:/usr/lib/nagios/plugins# head -n 1 check_mongodb.py
#!/usr/bin/env python
On this monitoring server, running Ubuntu 16.04 Xenial, there are python2 and python3 co-existant with the python command pointing to python2:
root@mon:~# ll /usr/bin/python
lrwxrwxrwx 1 root root 9 Nov 24 2017 /usr/bin/python -> python2.7
Note: This is the default until very recent Linux distributions. Only from this year (2020) on, python2 will be gone from new distro releases.
By adjusting the script interpreter to use python3, the plugin should now work, right?
root@mon:/usr/lib/nagios/plugins# head -n 1 check_mongodb.py
#!/usr/bin/env python3
root@mon:/usr/lib/nagios/plugins# ./check_mongodb.py -H 10.10.160.13 -P 30000 --all-databases -A database_size
No module named 'pymongo'
Ah! OK now that the script was changed to use python3, the plugin's requirement (pymongo module) also needs to be installed for python3, not just for python2!
root@mon:~# apt install python3-pip
root@mon:~# pip3 install pymongo
Let's try this again, shall we?
root@mon:/usr/lib/nagios/plugins# ./check_mongodb.py -H 10.10.160.13 -P 30000 --all-databases -A database_size
CRITICAL - Total size: 545850 MB; Database db1 size: 78 MB; Database db2 size: 10398 MB; Database metrics size: 531602 MB; Database open size: 351 MB; Database mief size: 2320 MB; Database wuff size: 7 MB; Database local size: 1094 MB; Database nagios size: 0 MB
And the plugin works (again)! What I'm still not sure of is why it stopped working on python2 in the first place. It might be working on MongoDB 2.x and 3.x with python2 but not on MongoDB 4.x.
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder