projects
/
ansible.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7fdacc0
)
fix log-anon script
author
Ralf Jung
<post@ralfj.de>
Sat, 2 Jun 2018 07:48:20 +0000
(09:48 +0200)
committer
Ralf Jung
<post@ralfj.de>
Sat, 2 Jun 2018 07:48:20 +0000
(09:48 +0200)
roles/apache/files/log-anon
patch
|
blob
|
history
diff --git
a/roles/apache/files/log-anon
b/roles/apache/files/log-anon
index 51775a09697cda6715dced5e6c7386addca0f46f..32b6c1e58b61d417495b463b82a37bec71a2fd64 100644
(file)
--- a/
roles/apache/files/log-anon
+++ b/
roles/apache/files/log-anon
@@
-1,6
+1,6
@@
#!/usr/bin/python
import sys, re
#!/usr/bin/python
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]
if len(sys.argv) != 2:
print >>sys.stderr, "Usage: %s filename" % sys.argv[0]
@@
-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"( .*)$")
# 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()
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")
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()
# not actually an IP address...
log.write(line)
log.flush()