Commit 43fc2f2e authored by Rafael Monnerat's avatar Rafael Monnerat 👻

wip

parent c41bd8a7
import re
import time
import sys
import gzip
r = re.compile("^(\[[^\]]+\]) (\[[^\]]+\]) (.*)$")
log_file = sys.argv[1]
MAXIMUM_DELAY = 0
VERBOSE = 0
BLOCK_SIZE = 4096
error_amount = 0
no_route_error = 0
network_is_unreacheable = 0
timeout = 0
def test(log_file, maximum_delay):
with open(log_file) as f:
f.seek(0, 2)
block_end_byte = f.tell()
if not BLOCK_SIZE:
BLOCK_SIZE = block_end_byte
f.seek(-min(block_end_byte, BLOCK_SIZE), 1)
data = f.read()
for line in reversed(data.splitlines()):
m = r.match(line)
if m is None:
continue
dt, level, msg = m.groups()
t = time.strptime(dt[1:-1], "%a %b %d %H:%M:%S %Y")
if maximum_delay and (time.time()-time.mktime(t)) > maximum_delay:
# no result in the latest hour
break
if level != "[error]":
continue
# Classify the types of errors
if "(113)No route to host" in msg:
no_route_error += 1
elif "(101)Network is unreachable" in msg:
network_is_unreacheable += 1
elif "(110)Connection timed out" in msg:
timeout += 1
error_amount += 1
if error_amount:
return "ERROR=%s (NOTROUTE=%s, UNREACHEABLENET=%s, TIMEOUT=%s)" % (error_amount, no_route_error, network_is_unreacheable, timeout)
return "OK"
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--log-file", metavar="LOG_FILE")
parser.add_argument("-d", "--maximun-delay", metavar="MAXIMUM_DELAY", default=0)
args = parser.parse_args()
log_file = args.log_file
result = test(args.log_file, args.maximum_delay)
print result
if result != "OK":
sys.exit(1)
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