Error when using check_docker.py

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
dclsystems
Posts: 14
Joined: Wed Dec 13, 2017 5:33 pm

Error when using check_docker.py

Post by dclsystems »

I am getting error while using https://nagiosxi.distributel.net/nagios ... _docker.py file:

root@docker:/usr/local/ncpa/plugins# python /usr/local/ncpa/plugins/check_docker.py -H http://127.0.0.1:2375 -s /var/run/docker.sock --check-type 'containers_healthy' --all -t 0 --ignore-no-healthcheck -l -w '50:' -c '30:'
Traceback (most recent call last):
File "/usr/local/ncpa/plugins/check_docker.py", line 988, in <module>
_ = main()
File "/usr/local/ncpa/plugins/check_docker.py", line 959, in main
checks = choose_checks(options)
File "/usr/local/ncpa/plugins/check_docker.py", line 226, in choose_checks
check_data = get_threshold_maps(options.warning, options.critical, selection)
File "/usr/local/ncpa/plugins/check_docker.py", line 329, in get_threshold_maps
for triplet in zip(attrs.keys(), warning_list, critical_list):
AttributeError: 'list' object has no attribute 'keys'

RD
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Error when using check_docker.py

Post by npolovenko »

Hello, @dclsystems. First, let's make sure that you have installed all the required python modules. Please run the following commands in order, from the command line and let me know if at least one of them errors out.

Code: Select all

su nagios -c 'python -c "import sys"'
su nagios -c 'python -c "import optparse"'
su nagios -c 'python -c "from os.path import expanduser"'
su nagios -c 'python -c "import subprocess"'
su nagios -c 'python -c "import urllib"'
su nagios -c 'python -c "import json"'
su nagios -c 'python -c "import shlex"'
su nagios -c 'python -c "import signal"'
su nagios -c 'from copy import copy"'
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
emarmonti
Posts: 26
Joined: Fri Mar 29, 2013 10:06 am

Re: Error when using check_docker.py

Post by emarmonti »

Hello,

I am receiving the same error. I ran the commands you suggested. They error out with:

Code: Select all

[root@ma1p-nagiosxi ~]# su nagios -c 'from copy import copy"'
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
[root@ma1p-nagiosxi ~]#
I'm not sure exactly what this command is supposed to do, but the " is throwing it off, and also there is no "from" command installed so I'm thinking maybe that is supposed to be something completely different and you just had a typo or two?


I still receive this error:
File "/usr/local/ncpa/plugins/check_docker.py", line 988, in <module>
_ = main()
File "/usr/local/ncpa/plugins/check_docker.py", line 959, in main
checks = choose_checks(options)
File "/usr/local/ncpa/plugins/check_docker.py", line 226, in choose_checks
check_data = get_threshold_maps(options.warning, options.critical, selection)
File "/usr/local/ncpa/plugins/check_docker.py", line 329, in get_threshold_maps
for triplet in zip(attrs.keys(), warning_list, critical_list):
AttributeError: 'list' object has no attribute 'keys'

This is after following instructions at https://assets.nagios.com/downloads/nag ... ios-XI.pdf and successfully going through the wizard to modify a docker host (via ncpa).

npolovenko wrote:Hello, @dclsystems. First, let's make sure that you have installed all the required python modules. Please run the following commands in order, from the command line and let me know if at least one of them errors out.

Code: Select all

su nagios -c 'python -c "import sys"'
su nagios -c 'python -c "import optparse"'
su nagios -c 'python -c "from os.path import expanduser"'
su nagios -c 'python -c "import subprocess"'
su nagios -c 'python -c "import urllib"'
su nagios -c 'python -c "import json"'
su nagios -c 'python -c "import shlex"'
su nagios -c 'python -c "import signal"'
su nagios -c 'from copy import copy"'
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Error when using check_docker.py

Post by npolovenko »

@emarmonti, Sorry, I didn't spell the last command right. Please try:

Code: Select all

su nagios -c 'python -c "from copy import copy"'
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
emarmonti
Posts: 26
Joined: Fri Mar 29, 2013 10:06 am

Re: Error when using check_docker.py

Post by emarmonti »

Unfortunately running that command manually and then forcing a check on my "Docker - Container *" checks yields the same error. I can see that check_docker.py already is importing all of these modules.

Here is the error:

Code: Select all

File "/usr/local/ncpa/plugins/check_docker.py", line 988, in <module>
_ = main()
File "/usr/local/ncpa/plugins/check_docker.py", line 959, in main
checks = choose_checks(options)
File "/usr/local/ncpa/plugins/check_docker.py", line 226, in choose_checks
check_data = get_threshold_maps(options.warning, options.critical, selection)
File "/usr/local/ncpa/plugins/check_docker.py", line 329, in get_threshold_maps
for triplet in zip(attrs.keys(), warning_list, critical_list):
AttributeError: 'list' object has no attribute 'keys'
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Error when using check_docker.py

Post by mcapra »

Can you share the output of:

Code: Select all

sudo docker version
python --version
I can't actually get this plugin to work against:

Code: Select all

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 03:47:25 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Code: Select all

# python check_docker.py -H http:/v1.39/ -s /var/run/docker.sock --check-type 'containers_cpu'
Traceback (most recent call last):
  File "check_docker.py", line 988, in <module>
    _ = main()
  File "check_docker.py", line 959, in main
    checks = choose_checks(options)
  File "check_docker.py", line 226, in choose_checks
    check_data = get_threshold_maps(options.warning, options.critical, selection)
  File "check_docker.py", line 329, in get_threshold_maps
    for triplet in zip(attrs.keys(), warning_list, critical_list):
AttributeError: 'list' object has no attribute 'keys'
Despite the socket responding to cURL:

Code: Select all

# curl --unix-socket /var/run/docker.sock http:/v1.39/containers/json
## Valid JSON shows up
Former Nagios employee
https://www.mcapra.com/
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Error when using check_docker.py

Post by npolovenko »

Thanks, @mcapra.
@emarmonti, Please provide us with the versions.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
emarmonti
Posts: 26
Joined: Fri Mar 29, 2013 10:06 am

Re: Error when using check_docker.py

Post by emarmonti »

Hello!

Docker wasn't actually installed on the Nagios XI Server. Given the fact that the Docker wizard was already installed, I kind of assumed all dependencies would exist to use it.

I went ahead and installed docker-ce. The check is still failing. Here are the version numbers you were asking for.

Code: Select all

[emarmonti@ma1p-nagiosxi ~]$ docker --version
Docker version 18.09.6, build 481bc77156
[emarmonti@ma1p-nagiosxi ~]$ python --version
Python 2.7.5
[emarmonti@ma1p-nagiosxi ~]$
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Error when using check_docker.py

Post by npolovenko »

@emarmonti, We found a bug in the plugin and submitted a task for the dev team. Please check back in this thread some time next week for an update. Once the bug fix has been released, we'll provide you with the new version.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Error when using check_docker.py

Post by npolovenko »

@emarmonti, UPDATE: Please move the existing check_docker plugin to a backup directory and use the modified plugin I attached to this message:

Code: Select all

mv /usr/local/nagios/libexec/check_docker.py /tmp/
Don't forget to give permissions to the new plugin before executing it:

Code: Select all

chmod 777 /usr/local/nagios/libexec/check_docker.py
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked