in src/main/java/com/googlesource/gerrit/plugins/auditsl4j/logsource/HTTPLog.java [71:103]
public static Optional<HTTPLog> createFromLog(String line) {
// HTTP log example:
// 104.32.164.100 - - [24/Jan/2019:00:00:03 +0000] "GET /plugins/events-log/ HTTP/1.1" 404 9 -
// "Apache-HttpClient/4.5.3 (Java/1.8.0_191)"
Matcher a =
Pattern.compile(
"^(?<ip>.*?)\\s-\\s(?<user>.*?)\\s\\["
+ "(?<timestamp>.*?)\\]\\s\""
+ "(?<method>\\w+)\\s(?<resource>.*?)\\s(?<protocol>.*?)\"\\s"
+ "(?<status>\\d+)\\s(?<contentLength>\\d+|-)\\s(?<referrer>.*?)\\s(?<userAgent>.*?)$")
.matcher(line);
if (a.matches()) {
try {
return Optional.of(
new HTTPLog(
a.group("ip"),
a.group("user"),
a.group("timestamp"),
a.group("method"),
a.group("resource"),
a.group("protocol"),
Integer.parseInt(a.group("status")),
a.group("contentLength"),
a.group("referrer"),
a.group("userAgent")));
} catch (Exception e) {
log.error("Something wrong while parsing line: " + line);
}
} else {
log.error("Can't extract any info from line: " + line);
}
return Optional.empty();
}