elacheche / docker_check

A NAGIOS compatible plugin to check docker containers stats
GNU General Public License v3.0
15 stars 7 forks source link

icinga2 bug #1

Closed zaraquer closed 7 years ago

zaraquer commented 7 years ago

If I run the script from terminel, I get the right output, but in icinga2 I only got this: UNKNOWN - check_by_ssh: Remote command '/usr/lib/nagios/plugins/docker_check.py' returned status 255

elacheche commented 7 years ago

Did you downloaded the script to your Docker server as mentioned in the Get the script to the right path in the Docker server section?

There is a step that I forgot to mention in the README file, you need to accept the remote server fingerprint, that can be done by doing "ssh foo@remote-server.bar"..

Did you used the by_ssh method before? If not, you need to setup a paswordless ssh key for the nagios user to be able to communicate with the server without asking for a passowrd..

zaraquer commented 7 years ago

The icinga2 service and the docker service is on the same server now, just because I testing how can i monitor the containers. In this case the setup is different? And thank you for the fast reply!

elacheche commented 7 years ago

You're welcome..

Yeah, that'll be a little bit different than a remote server.. As the 2 services are running from the same host, you can ignore the by_ssh thing..

In the commands.conf file, you can use this instead of the one mentioned in the README:

object CheckCommand "check_docker" {
        command = [ PluginDir + "/docker_check.py"]
}

As you can notice, in that block I removed the by-ssh import, and changed the CheckCommand name, don't forget to use the name you used in this object to call it in the other steps..

zaraquer commented 7 years ago

Thanks, that error is disappeared, but now icinga ask me for the docker module which is installed already. No module named 'docker': Please install the docker module, you can use' ''pip install docker' to do that

root@xy:/usr/lib/nagios/plugins# pip install docker Requirement already satisfied (use --upgrade to upgrade): docker in /usr/local/lib/python2.7/dist-packages Cleaning up...

elacheche commented 7 years ago

My fault, I should've mention that you should use pip3, because the script is based on Python3..

This should solve the issue:

pip3 install docker

zaraquer commented 7 years ago

I had a much longger issue after the pip3 install. And of couse, thanks for the very help! Yet, I dont get it what kind of permission is missing..

Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.4/http/client.py", line 1125, in request self._send_request(method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1163, in _send_request self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1121, in endheaders self._send_output(message_body) File "/usr/lib/python3.4/http/client.py", line 951, in _send_output self.send(msg) File "/usr/lib/python3.4/http/client.py", line 886, in send self.connect() File "/usr/local/lib/python3.4/dist-packages/docker/transport/unixconn.py", line 33, in connect sock.connect(self.unix_socket) PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send timeout=timeout File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/retry.py", line 347, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/packages/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.4/http/client.py", line 1125, in request self._send_request(method, url, body, headers) File "/usr/lib/python3.4/http/client.py", line 1163, in _send_request self.endheaders(body) File "/usr/lib/python3.4/http/client.py", line 1121, in endheaders self._send_output(message_body) File "/usr/lib/python3.4/http/client.py", line 951, in _send_output self.send(msg) File "/usr/lib/python3.4/http/client.py", line 886, in send self.connect() File "/usr/local/lib/python3.4/dist-packages/docker/transport/unixconn.py", line 33, in connect sock.connect(self.unix_socket) requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/nagios/plugins/docker_check.py", line 114, in main() File "/usr/lib/nagios/plugins/docker_check.py", line 57, in main docker.from_env().containers.list() File "/usr/local/lib/python3.4/dist-packages/docker/models/containers.py", line 769, in list since=since) File "/usr/local/lib/python3.4/dist-packages/docker/api/container.py", line 189, in containers res = self._result(self._get(u, params=params), True) File "/usr/local/lib/python3.4/dist-packages/docker/utils/decorators.py", line 47, in inner return f(self, *args, kwargs) File "/usr/local/lib/python3.4/dist-packages/docker/api/client.py", line 183, in _get return self.get(url, self._set_request_timeout(kwargs)) File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 501, in get return self.request('GET', url, kwargs) File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 488, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 473, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

elacheche commented 7 years ago

That's the output of pip or the script?

Can you please execute the script from cli and share the output?

zaraquer commented 7 years ago

This is the output of the script in icinga.

But still, if I run it in commandline, its ok root@xy:/usr/lib/nagios/plugins# python /usr/lib/nagios/plugins/docker_check.py OK | nexus_mem_pct=40.0% nexus_cpu_pct=0.45% nexus_net_in=830 nexus_net_out=648 nexus_disk_in=411062272 nexus_disk_out=908083200 sonarqube_mem_pct=23.0% sonarqube_cpu_pct=0.32% sonarqube_net_in=18853969 sonarqube_net_out=10179385 sonarqube_disk_in=1014980608 sonarqube_disk_out=192942080

elacheche commented 7 years ago

Can you please join me on IRC.. It'll be faster to discuss this directly instead of using Github as a chatting platform :)