Wait that Nagios creates its FIFO file

Change-Id: I1a78db73be23d65bf021a561b7b330f893202f2d
Closes-bug: #1595975
This commit is contained in:
Swann Croiset 2016-06-24 16:33:57 +02:00
parent 7bd09ef2be
commit 4a92604de2
1 changed files with 11 additions and 1 deletions

View File

@ -17,6 +17,7 @@
# command PROCESS_SERVICE_CHECK_RESULT
#
import os
import time
from urlparse import parse_qs
@ -25,6 +26,10 @@ PROCESS_CHECK_CMD = 'PROCESS_SERVICE_CHECK_RESULT'
VALID_STATES = range(0, 4)
class NagiosNotReady(Exception):
pass
def http_response(response, status_string, output=None):
if output is None:
output = ''
@ -79,6 +84,9 @@ def validate_params(params):
def write_command(cmd_file, p, timestamp):
if not os.path.exists(cmd_file):
raise NagiosNotReady()
cmd = "[{timestamp}] {cmd};{host};{service};{state};{output}".format(
timestamp=timestamp,
cmd=PROCESS_CHECK_CMD,
@ -112,7 +120,9 @@ def application(environ, response):
cmd_file = environ.get('NAGIOS_CMD_FILE', '/var/lib/nagios3/rw/nagios.cmd')
try:
write_command(cmd_file, params, timestamp)
except e:
except NagiosNotReady:
return http_response(response, '503 Service Unavailable')
except Exception as e:
return http_response(response, '500 Internal Server Error', str(e))
return http_response(response, '204 No Content')