添加App和DDos日志查询接口

This commit is contained in:
zhangdongxu
2018-07-06 09:06:08 +08:00
parent 0a67a013cd
commit 6f23ea08b9
5 changed files with 276 additions and 17 deletions

View File

@@ -0,0 +1,15 @@
package com.nis.domain.restful;
import com.nis.domain.LogEntity;
/**
* @ClassName:NtcAppLog
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年7月5日 下午6:21:55
* @version V1.0
*/
public class NtcAppLog extends LogEntity<NtcAppLog> {
private static final long serialVersionUID = -1186780816038898916L;
}

View File

@@ -0,0 +1,83 @@
package com.nis.domain.restful;
import java.util.Date;
import com.nis.domain.LogEntity;
import com.wordnik.swagger.annotations.ApiModelProperty;
/**
* @ClassName:NtcDdosLog
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年7月5日 下午6:01:18
* @version V1.0
*/
public class NtcDdosLog extends LogEntity<NtcDdosLog> {
private static final long serialVersionUID = -2918327495094410549L;
@ApiModelProperty(value = "攻击类型", required = true)
protected Integer attackType;
@ApiModelProperty(value = "攻击起始时间", required = true)
protected Date attackStartTime;
@ApiModelProperty(value = "最后一次攻击包时间", required = true)
protected Date lastAttackTime;
@ApiModelProperty(value = "攻击最大流量, 包数/秒", required = true)
protected String attackMaxPps;
@ApiModelProperty(value = "攻击最大流量, bit数/秒", required = true)
protected String attackMaxBps;
@ApiModelProperty(value = "攻击累积包数", required = true)
protected String attackTotalPkt;
@ApiModelProperty(value = "攻击累积字节数", required = true)
protected String attackTotalByte;
@ApiModelProperty(value = "攻击流量是否被丢弃", required = true)
protected Integer isBlcok;
public Integer getAttackType() {
return attackType;
}
public void setAttackType(Integer attackType) {
this.attackType = attackType;
}
public Date getAttackStartTime() {
return attackStartTime;
}
public void setAttackStartTime(Date attackStartTime) {
this.attackStartTime = attackStartTime;
}
public Date getLastAttackTime() {
return lastAttackTime;
}
public void setLastAttackTime(Date lastAttackTime) {
this.lastAttackTime = lastAttackTime;
}
public String getAttackMaxPps() {
return attackMaxPps;
}
public void setAttackMaxPps(String attackMaxPps) {
this.attackMaxPps = attackMaxPps;
}
public String getAttackMaxBps() {
return attackMaxBps;
}
public void setAttackMaxBps(String attackMaxBps) {
this.attackMaxBps = attackMaxBps;
}
public String getAttackTotalPkt() {
return attackTotalPkt;
}
public void setAttackTotalPkt(String attackTotalPkt) {
this.attackTotalPkt = attackTotalPkt;
}
public String getAttackTotalByte() {
return attackTotalByte;
}
public void setAttackTotalByte(String attackTotalByte) {
this.attackTotalByte = attackTotalByte;
}
public Integer getIsBlcok() {
return isBlcok;
}
public void setIsBlcok(Integer isBlcok) {
this.isBlcok = isBlcok;
}
}

View File

@@ -18,6 +18,8 @@ import org.springframework.web.bind.annotation.RestController;
import com.nis.domain.LogEntity;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcAppLog;
import com.nis.domain.restful.NtcDdosLog;
import com.nis.domain.restful.NtcDnsLog;
import com.nis.domain.restful.NtcFtpLog;
import com.nis.domain.restful.NtcHttpLog;
@@ -148,7 +150,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcHttpLog,
Configurations.getStringProperty(NtcHttpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcHttpLog.class.getSimpleName() + "HiveTable", "ntc_http_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcHttpLog.class, "foundTime",
"recvTime");
@@ -208,7 +210,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcDnsLog,
Configurations.getStringProperty(NtcDnsLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcDnsLog.class.getSimpleName() + "HiveTable", "ntc_dns_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcDnsLog.class, "foundTime",
"recvTime");
@@ -268,7 +270,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcMailLog,
Configurations.getStringProperty(NtcMailLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcMailLog.class.getSimpleName() + "HiveTable", "ntc_mail_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcMailLog.class, "foundTime",
"recvTime");
@@ -328,7 +330,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcSslLog,
Configurations.getStringProperty(NtcSslLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcSslLog.class.getSimpleName() + "HiveTable", "ntc_ssl_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcSslLog.class, "foundTime",
"recvTime");
@@ -388,7 +390,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcPptpLog,
Configurations.getStringProperty(NtcPptpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcPptpLog.class.getSimpleName() + "HiveTable", "ntc_pptp_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcPptpLog.class, "foundTime",
"recvTime");
@@ -447,7 +449,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcL2tpLog,
Configurations.getStringProperty(NtcL2tpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcL2tpLog.class.getSimpleName() + "HiveTable", "ntc_l2tp_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcL2tpLog.class, "foundTime",
"recvTime");
@@ -507,7 +509,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcOpenvpnLog,
Configurations.getStringProperty(NtcOpenvpnLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcOpenvpnLog.class.getSimpleName() + "HiveTable", "ntc_openvpn_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcOpenvpnLog.class, "foundTime",
"recvTime");
@@ -567,7 +569,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcIpsecLog,
Configurations.getStringProperty(NtcIpsecLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcIpsecLog.class.getSimpleName() + "HiveTable", "ntc_ipsec_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcIpsecLog.class, "foundTime",
"recvTime");
@@ -627,7 +629,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcSshLog,
Configurations.getStringProperty(NtcSshLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcSshLog.class.getSimpleName() + "HiveTable", "ntc_ssh_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcSshLog.class, "foundTime",
"recvTime");
@@ -687,7 +689,7 @@ public class LogController extends BaseRestController {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcFtpLog,
Configurations.getStringProperty(NtcFtpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
Configurations.getStringProperty(NtcFtpLog.class.getSimpleName() + "HiveTable", "ntc_ftp_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcFtpLog.class, "foundTime",
"recvTime");
@@ -723,7 +725,122 @@ public class LogController extends BaseRestController {
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "FTP日志检索成功",
ntcFtpLogPage, 0);
}
@RequestMapping(value = "/ntcAppLogs", method = RequestMethod.GET)
@ApiOperation(value = "App日志查询", httpMethod = "GET", notes = "对应配置为“App管理”存储动作为阻断与监测的命中日志。对日志功能“APP策略日志”提供数据基础查询服务")
public Map<String, ?> ntcAppLogs(Page page, NtcAppLog ntcAppLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcAppLog> ntcAppLogPage = null;
try {
resetTime(ntcAppLog);
testService.queryConditionCheck(auditLogThread, start, ntcAppLog, NtcAppLog.class, page);
ntcAppLogPage = new Page<NtcAppLog>();
ntcAppLogPage.setPageNo(page.getPageNo());
ntcAppLogPage.setPageSize(page.getPageSize());
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcAppLog.class.getSimpleName(), page.getOrderBy());
} else {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcAppLog,
Configurations.getStringProperty(NtcAppLog.class.getSimpleName() + "HiveTable", "ntc_app_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcAppLog.class, "foundTime",
"recvTime");
if (tableMapping == null) {
ntcAppLogPage.setList(new ArrayList());
} else {
List list = new ArrayList();
if (tableMapping.get("obj").size() > page.getPageSize()) {
list = tableMapping.get("obj").subList(0, page.getPageSize());
} else {
list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size());
}
if (list.size() > 0) {
String jsonString = JsonMapper.toJsonString(list);
List<NtcAppLog> List = (java.util.List<NtcAppLog>) JsonMapper.fromJsonList(jsonString,
NtcAppLog.class);
ntcAppLogPage.setList(List);
ntcAppLogPage.setCount(List.size());
} else {
ntcAppLogPage.setList(new ArrayList());
}
}
} catch (Exception e) {
e.printStackTrace();
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
if (!(e instanceof RestServiceException)) {
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "App日志检索失败");
}
throw ((RestServiceException) e);
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App日志检索成功",
ntcAppLogPage, 0);
}
@RequestMapping(value = "/ntcDdosLogs", method = RequestMethod.GET)
@ApiOperation(value = "DDos日志查询", httpMethod = "GET", notes = "对应配置为“DDOS日志监控”存储动作为丢弃的命中日志。对日志功能“DDOS日志监控”提供数据基础查询服务")
public Map<String, ?> ntcDdosLogs(Page page, NtcDdosLog ntcDdosLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcDdosLog> ntcDdosLogPage = null;
try {
resetTime(ntcDdosLog);
testService.queryConditionCheck(auditLogThread, start, ntcDdosLog, NtcDdosLog.class, page);
ntcDdosLogPage = new Page<NtcDdosLog>();
ntcDdosLogPage.setPageNo(page.getPageNo());
ntcDdosLogPage.setPageSize(page.getPageSize());
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = Page.getOrderBySql(NtcDdosLog.class.getSimpleName(), page.getOrderBy());
} else {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcDdosLog,
Configurations.getStringProperty(NtcDdosLog.class.getSimpleName() + "HiveTable", "ntc_ddos_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcDdosLog.class, "foundTime",
"recvTime");
if (tableMapping == null) {
ntcDdosLogPage.setList(new ArrayList());
} else {
List list = new ArrayList();
if (tableMapping.get("obj").size() > page.getPageSize()) {
list = tableMapping.get("obj").subList(0, page.getPageSize());
} else {
list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size());
}
if (list.size() > 0) {
String jsonString = JsonMapper.toJsonString(list);
List<NtcDdosLog> List = (java.util.List<NtcDdosLog>) JsonMapper.fromJsonList(jsonString,
NtcDdosLog.class);
ntcDdosLogPage.setList(List);
ntcDdosLogPage.setCount(List.size());
} else {
ntcDdosLogPage.setList(new ArrayList());
}
}
} catch (Exception e) {
e.printStackTrace();
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
if (!(e instanceof RestServiceException)) {
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "DDos日志检索失败");
}
throw ((RestServiceException) e);
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "DDos日志检索成功",
ntcDdosLogPage, 0);
}
@RequestMapping(value = "/ntcPzReport", method = RequestMethod.GET)
@ApiOperation(value = "配置日志总量统计", httpMethod = "GET", notes = "配置命中日志数量实时统计报表,对外提供多种数据表现形式,具体可应用于界面配置命中总量业务、配置报表业务等")
public Map<String, ?> ntcPzReport(Page page, NtcPzReport ntcPzReport, Model model, HttpServletRequest request,

View File

@@ -306,13 +306,54 @@
<result column="ftp_content" jdbcType="VARCHAR" property="ftpContent" />
</resultMap>
<resultMap id="NtcAppLogMap" type="com.nis.domain.restful.NtcAppLog">
<result column="cfg_id" jdbcType="BIGINT" property="cfgId" />
<result column="found_Time" jdbcType="TIMESTAMP" property="foundTime" />
<result column="recv_Time" jdbcType="TIMESTAMP" property="recvTime" />
<result column="trans_proto" jdbcType="VARCHAR" property="transProto" />
<result column="addr_type" jdbcType="INTEGER" property="addrType" />
<result column="d_ip" jdbcType="VARCHAR" property="dIp" />
<result column="s_ip" jdbcType="VARCHAR" property="sIp" />
<result column="d_port" jdbcType="VARCHAR" property="dPort" />
<result column="s_port" jdbcType="VARCHAR" property="sPort" />
<result column="service" jdbcType="INTEGER" property="service" />
<result column="entrance_id" jdbcType="BIGINT" property="entranceId" />
<result column="device_id" jdbcType="INTEGER" property="deviceId" />
<result column="direction" jdbcType="INTEGER" property="direction" />
<result column="stream_dir" jdbcType="INTEGER" property="streamDir" />
<result column="cap_ip" jdbcType="VARCHAR" property="capIp" />
<result column="addr_list" jdbcType="VARCHAR" property="addrList" />
<result column="user_region" jdbcType="VARCHAR" property="userRegion" />
</resultMap>
<resultMap id="NtcDdosLogMap" type="com.nis.domain.restful.NtcDdosLog">
<result column="cfg_id" jdbcType="BIGINT" property="cfgId" />
<result column="found_Time" jdbcType="TIMESTAMP" property="foundTime" />
<result column="recv_Time" jdbcType="TIMESTAMP" property="recvTime" />
<result column="trans_proto" jdbcType="VARCHAR" property="transProto" />
<result column="addr_type" jdbcType="INTEGER" property="addrType" />
<result column="d_ip" jdbcType="VARCHAR" property="dIp" />
<result column="s_ip" jdbcType="VARCHAR" property="sIp" />
<result column="d_port" jdbcType="VARCHAR" property="dPort" />
<result column="s_port" jdbcType="VARCHAR" property="sPort" />
<result column="service" jdbcType="INTEGER" property="service" />
<result column="entrance_id" jdbcType="BIGINT" property="entranceId" />
<result column="device_id" jdbcType="INTEGER" property="deviceId" />
<result column="direction" jdbcType="INTEGER" property="direction" />
<result column="stream_dir" jdbcType="INTEGER" property="streamDir" />
<result column="cap_ip" jdbcType="VARCHAR" property="capIp" />
<result column="addr_list" jdbcType="VARCHAR" property="addrList" />
<result column="user_region" jdbcType="VARCHAR" property="userRegion" />
<result column="attack_type" jdbcType="INTEGER" property="attackType" />
<result column="attack_start_time" jdbcType="TIMESTAMP" property="attackStartTime" />
<result column="last_attack_time" jdbcType="TIMESTAMP" property="lastAttackTime" />
<result column="attack_max_pps" jdbcType="VARCHAR" property="attackMaxPps" />
<result column="attack_max_bps" jdbcType="VARCHAR" property="attackMaxBps" />
<result column="attack_total_pkt" jdbcType="VARCHAR" property="attackTotalPkt" />
<result column="attack_total_byte" jdbcType="VARCHAR" property="attackTotalByte" />
<result column="is_blcok" jdbcType="INTEGER" property="isBlcok" />
</resultMap>

View File

@@ -10,6 +10,9 @@ NtcOpenvpnLogHiveTable=NTC_OPENVPN_LOG
NtcIpsecLogHiveTable=NTC_IPSEC_LOG
NtcSshLogHiveTable=NTC_SSH_LOG
NtcFtpLogHiveTable=NTC_FTP_LOG
NtcAppLogHiveTable=NTC_APP_LOG
NtcDdosLogHiveTable=NTC_DDOS_LOG