|
|
package com.yoho.ops.maliciousdetection;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
/**
|
|
|
* Gateway 访问日志
|
|
|
* @author chunhua.zhang@yoho.cnm
|
|
|
* File Pattern: 本地IP|用户IP|当前时间|HTTP请求方式|User-Agent|请求标示|请求参数|HTTP响应码|请求处理时间
|
|
|
*/
|
|
|
public class GatewayAccessLog implements Serializable {
|
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(GatewayAccessLog.class.getClass());
|
|
|
|
|
|
|
|
|
private String localIp;
|
|
|
private String userIp;
|
|
|
private String time;
|
|
|
private String httpMethod;
|
|
|
private String userAgent;
|
|
|
private String method;
|
|
|
private String params;
|
|
|
private int reponseCode;
|
|
|
private int cost;
|
|
|
|
|
|
public GatewayAccessLog(String localIp, String userIp, String time, String httpMethod, String userAgent, String method, String params, int reponseCode, int cost) {
|
|
|
this.localIp = localIp;
|
|
|
this.userIp = userIp;
|
|
|
this.time = time;
|
|
|
this.httpMethod = httpMethod;
|
|
|
this.userAgent = userAgent;
|
|
|
this.method = method;
|
|
|
this.params = params;
|
|
|
this.reponseCode = reponseCode;
|
|
|
this.cost = cost;
|
|
|
}
|
|
|
|
|
|
public GatewayAccessLog() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 解析日志
|
|
|
*
|
|
|
* @param logline
|
|
|
* @return
|
|
|
*/
|
|
|
public static GatewayAccessLog parseFromLogLine(String logline) {
|
|
|
|
|
|
// 本地IP|用户IP|当前时间|HTTP请求方式|User-Agent|请求标示|请求参数|HTTP响应码|请求处理时间
|
|
|
if (StringUtils.isEmpty(logline)) {
|
|
|
return null;
|
|
|
}
|
|
|
String[] params = logline.split("\\|");
|
|
|
if (params == null || params.length < 9) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
int httpResponseCode = 200;
|
|
|
int cost = 0;
|
|
|
try{
|
|
|
httpResponseCode = Integer.parseInt(params[7]);
|
|
|
cost = Integer.parseInt(params[8]);
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
return new GatewayAccessLog(params[0], params[1], params[2], params[3],
|
|
|
params[4], params[5], params[6], httpResponseCode, cost);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
return String.format("%s|%s|%s|%s|%s|%s|%s|%d|%d",
|
|
|
localIp, userIp, time, httpMethod, userAgent, method,
|
|
|
params, reponseCode, cost);
|
|
|
}
|
|
|
|
|
|
public String getLocalIp() {
|
|
|
return localIp;
|
|
|
}
|
|
|
|
|
|
public void setLocalIp(String localIp) {
|
|
|
this.localIp = localIp;
|
|
|
}
|
|
|
|
|
|
public String getUserIp() {
|
|
|
return userIp;
|
|
|
}
|
|
|
|
|
|
public void setUserIp(String userIp) {
|
|
|
this.userIp = userIp;
|
|
|
}
|
|
|
|
|
|
public String getTime() {
|
|
|
return time;
|
|
|
}
|
|
|
|
|
|
public void setTime(String time) {
|
|
|
this.time = time;
|
|
|
}
|
|
|
|
|
|
public String getHttpMethod() {
|
|
|
return httpMethod;
|
|
|
}
|
|
|
|
|
|
public void setHttpMethod(String httpMethod) {
|
|
|
this.httpMethod = httpMethod;
|
|
|
}
|
|
|
|
|
|
public String getUserAgent() {
|
|
|
return userAgent;
|
|
|
}
|
|
|
|
|
|
public void setUserAgent(String userAgent) {
|
|
|
this.userAgent = userAgent;
|
|
|
}
|
|
|
|
|
|
public String getMethod() {
|
|
|
return method;
|
|
|
}
|
|
|
|
|
|
public void setMethod(String method) {
|
|
|
this.method = method;
|
|
|
}
|
|
|
|
|
|
public String getParams() {
|
|
|
return params;
|
|
|
}
|
|
|
|
|
|
public void setParams(String params) {
|
|
|
this.params = params;
|
|
|
}
|
|
|
|
|
|
public int getReponseCode() {
|
|
|
return reponseCode;
|
|
|
}
|
|
|
|
|
|
public void setReponseCode(int reponseCode) {
|
|
|
this.reponseCode = reponseCode;
|
|
|
}
|
|
|
|
|
|
public int getCost() {
|
|
|
return cost;
|
|
|
}
|
|
|
|
|
|
public void setCost(int cost) {
|
|
|
this.cost = cost;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|