X-Git-Url: https://git.ralfj.de/ansible.git/blobdiff_plain/dfc066052e57635234c8afed9010c38f55e5cc78..c1d31e776f8c309aa5d5aa2f6441f665a1cfd90a:/roles/apache/files/log-anon diff --git a/roles/apache/files/log-anon b/roles/apache/files/log-anon index 51775a0..0b84668 100644 --- a/roles/apache/files/log-anon +++ b/roles/apache/files/log-anon @@ -1,9 +1,9 @@ -#!/usr/bin/python +#!/usr/bin/python3 import sys, re -from netaddr import IPAddress +from netaddr import IPAddress, AddrFormatError if len(sys.argv) != 2: - print >>sys.stderr, "Usage: %s filename" % sys.argv[0] + print("Usage: %s filename" % sys.argv[0], file=sys.stderr) sys.exit(1) log = open(sys.argv[1], "a") @@ -11,7 +11,7 @@ log = open(sys.argv[1], "a") # group 1 must be the prefix, group 2 the IP, group 3 the suffix ipmatch = r"([0-9a-f.:]+)" accesslog = re.compile(r"^(\S+ )"+ipmatch+r"( .*)$") -errorlog = re.compile(r"^(.* \[client )"+ipmatch+r"(\] .*)$") +errorlog = re.compile(r"^(.* \[client )"+ipmatch+r"(:[0-9]+\] .*)$") while True: line = sys.stdin.readline() @@ -33,7 +33,7 @@ while True: ip = ip & (IPAddress('255.255.255.0') if ip.version == 4 else IPAddress('ffff:ffff:ffff::')) # mask out a bunch of bits # now we have a parsed representation of the IP address we want to print log.write(prefix+str(ip)+suffix+"\n") - except (ValueError, netaddr.core.AddrFormatError): + except (ValueError, AddrFormatError): # not actually an IP address... log.write(line) log.flush()