Tag Archives: #NRPE

Change check_docker Nagios’ plugin over NRPE to list all of the Docker containers

Due to the way that NRPE/Nagios reads output from this fine plugin, it will show only the first running container in the Web-interface if asked for check_docker –status running. Python solves “printf” functionality by adding a suffix, so here’s a quick diff for the plugin so it can display all of the running containers when asked by check_docker plugin:

 

--- check_docker 2016-09-06 13:16:50.396425436 +0200
+++ /opt/nagios-plugins/check_docker/check_docker-master/check_docker.py 2016-05-16 03:20:13.000000000 +0200
@@ -1,5 +1,4 @@
 #!/usr/bin/env python3
-from __future__ import print_function
 __author__ = 'Tim Laurence'
 __copyright__ = "Copyright 2016"
 __credits__ = ['Tim Laurence']
@@ -15,6 +14,7 @@
 Note: I really would have preferred to have used requests for all the network connections but that would have added a
 dependency.
 '''
+
 from sys import argv
 from http.client import HTTPConnection
 from urllib.request import AbstractHTTPHandler, HTTPHandler, HTTPSHandler, OpenerDirector
@@ -25,6 +25,7 @@
 
 
 
+
 DEFAULT_SOCKET = '/var/run/docker.sock'
 DEFAULT_TIMEOUT = 10.0
 DEFAULT_PORT = 2375
@@ -273,15 +274,15 @@
 def print_results():
 if len(messages) > 0:
 if len(performance_data) > 0:
- print(messages[0] + '|' + performance_data[0], end=' ')
+ print(messages[0] + '|' + performance_data[0])
 else:
- print(messages[0], end=' ')
+ print(messages[0])
 for message in messages[1:]:
- print(message, end=' ')
+ print(message)
 if len(performance_data) > 1:
 print('|', end='')
 for data in performance_data[1:]:
- print(data, end=' ')
+ print(data)
 
 if __name__ == '__main__':