From 6f23ea08b90a1158929cc2440d6f595c34bebed2 Mon Sep 17 00:00:00 2001 From: zhangdongxu Date: Fri, 6 Jul 2018 09:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0App=E5=92=8CDDos=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/nis/domain/restful/NtcAppLog.java | 15 ++ .../com/nis/domain/restful/NtcDdosLog.java | 83 +++++++++++ .../web/controller/restful/LogController.java | 137 ++++++++++++++++-- .../java/com/nis/web/dao/DfLogSearchDao.xml | 55 ++++++- src/main/resources/table.properties | 3 + 5 files changed, 276 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/nis/domain/restful/NtcAppLog.java create mode 100644 src/main/java/com/nis/domain/restful/NtcDdosLog.java diff --git a/src/main/java/com/nis/domain/restful/NtcAppLog.java b/src/main/java/com/nis/domain/restful/NtcAppLog.java new file mode 100644 index 0000000..6b454e6 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/NtcAppLog.java @@ -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 { + + private static final long serialVersionUID = -1186780816038898916L; +} diff --git a/src/main/java/com/nis/domain/restful/NtcDdosLog.java b/src/main/java/com/nis/domain/restful/NtcDdosLog.java new file mode 100644 index 0000000..6b426f8 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/NtcDdosLog.java @@ -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 { + + 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; + } + +} diff --git a/src/main/java/com/nis/web/controller/restful/LogController.java b/src/main/java/com/nis/web/controller/restful/LogController.java index e7886b5..6f2dbb7 100644 --- a/src/main/java/com/nis/web/controller/restful/LogController.java +++ b/src/main/java/com/nis/web/controller/restful/LogController.java @@ -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 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 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 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 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 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 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 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 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 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 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 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 ntcAppLogPage = null; + try { + resetTime(ntcAppLog); + testService.queryConditionCheck(auditLogThread, start, ntcAppLog, NtcAppLog.class, page); + ntcAppLogPage = new Page(); + 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 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 List = (java.util.List) 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 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 ntcDdosLogPage = null; + try { + resetTime(ntcDdosLog); + testService.queryConditionCheck(auditLogThread, start, ntcDdosLog, NtcDdosLog.class, page); + ntcDdosLogPage = new Page(); + 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 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 List = (java.util.List) 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 ntcPzReport(Page page, NtcPzReport ntcPzReport, Model model, HttpServletRequest request, diff --git a/src/main/java/com/nis/web/dao/DfLogSearchDao.xml b/src/main/java/com/nis/web/dao/DfLogSearchDao.xml index c6ba3e9..4284ba6 100644 --- a/src/main/java/com/nis/web/dao/DfLogSearchDao.xml +++ b/src/main/java/com/nis/web/dao/DfLogSearchDao.xml @@ -306,13 +306,54 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/table.properties b/src/main/resources/table.properties index 476fc6f..5857579 100644 --- a/src/main/resources/table.properties +++ b/src/main/resources/table.properties @@ -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 +