Merge "Wait that Nagios creates its FIFO file"

This commit is contained in:
Jenkins 2016-06-24 16:09:27 +00:00 committed by Gerrit Code Review
commit d7d89723c7
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')