Commit 67777da8 authored by Rafael Monnerat's avatar Rafael Monnerat

promise/check_error_on_apache_log: Be tolerant with first partial line

   As we don't read entire file, the regex can eventually get
   garbage on the latest line to parse. This commit make it tolerant
   while check.
parent 0c33fe28
......@@ -11,6 +11,7 @@ def test(log_file, maximum_delay):
no_route_error = 0
network_is_unreacheable = 0
timeout = 0
parsing_failure = 0
with open(log_file) as f:
f.seek(0, 2)
......@@ -23,11 +24,21 @@ def test(log_file, maximum_delay):
if m is None:
continue
dt, level, msg = m.groups()
try:
try:
t = time.strptime(dt[1:-1], "%a %b %d %H:%M:%S %Y")
except ValueError:
# Fail to parser for the first time, try a different output.
t = time.strptime(dt[1:-1], "%a %b %d %H:%M:%S.%f %Y")
except ValueError:
# Probably it fail to parse
if parsing_failure < 3:
# Accept failure 2 times, as the line can be actually
# cut on the middle.
parsing_failure += 1
continue
raise
if maximum_delay and (time.time()-time.mktime(t)) > maximum_delay:
# no result in the latest hour
break
......@@ -50,7 +61,6 @@ def test(log_file, maximum_delay):
return "OK"
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--log-file", required=True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment