提交一版日志的action查询和展示

This commit is contained in:
chenjinsong
2018-06-14 10:37:59 +08:00
parent 7334247f5b
commit 30c6d43130
4 changed files with 110 additions and 46 deletions

View File

@@ -30,13 +30,19 @@ public class BaseLogEntity<T> extends BaseEntity<T> {
protected String userRegion; //用户自定义 protected String userRegion; //用户自定义
protected Integer functionId; protected Integer functionId;
protected Integer action;
//自定义字段 //自定义字段
protected String seltype;//选中类型,页面搜索用 protected String seltype;//选中类型,页面搜索用
protected String searchFoundStartTime;//开始时间格式为yyyy-mm-dd hh24:mi:ss protected String searchFoundStartTime;//开始时间格式为yyyy-mm-dd hh24:mi:ss
protected String searchFoundEndTime;//结束时间,格式同上 protected String searchFoundEndTime;//结束时间,格式同上
public Integer getAction() {
return action;
}
public void setAction(Integer action) {
this.action = action;
}
public Integer getFunctionId() { public Integer getFunctionId() {
return functionId; return functionId;
} }

View File

@@ -473,21 +473,31 @@ public class BaseController {
} }
} }
public void initLogServiceType(Model model, BaseLogEntity log) { public void setLogAction(BaseLogEntity log) {
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(log.getFunctionId()); List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(log.getFunctionId());
model.addAttribute("serviceList", serviceList); for (FunctionServiceDict dict : serviceList) {
if (dict.getServiceId().intValue() == log.getServiceType().intValue()) {
log.setAction(dict.getAction());
} }
}
}
//初始化查询值判断 //初始化查询值判断
public void initLogSearchValue(BaseLogEntity entry,Map<String, Object> params){ public void initLogSearchValue(BaseLogEntity entry,Map<String, Object> params){
params.put("operator", entry.getCurrentUser().getName());
params.put("opTime", DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
params.put("opAction", 4);
if (StringUtils.isNotBlank(entry.getSearchFoundStartTime())&&StringUtils.isNotBlank(entry.getSearchFoundEndTime())) { if (StringUtils.isNotBlank(entry.getSearchFoundStartTime())&&StringUtils.isNotBlank(entry.getSearchFoundEndTime())) {
params.put("searchFoundStartTime", entry.getSearchFoundStartTime()); params.put("searchFoundStartTime", entry.getSearchFoundStartTime());
params.put("searchFoundEndTime", entry.getSearchFoundEndTime()); params.put("searchFoundEndTime", entry.getSearchFoundEndTime());
}else{ }else{
//设置默认查询当前时间及前五分钟 //设置默认查询当前时间及前五分钟
String startTime = DateUtils.getDateTime(); String endTime = DateUtils.getDateTime();
Date dateEnd = new Date(new Date().getTime()-Constants.LOG_TIME_RANGE); Date dateStart = new Date(new Date().getTime() - Constants.LOG_TIME_RANGE);
String endTime = DateUtils.formatDateTime(dateEnd); String startTime = DateUtils.formatDateTime(dateStart);
params.put("searchFoundStartTime", startTime); params.put("searchFoundStartTime", startTime);
params.put("searchFoundEndTime",endTime ); params.put("searchFoundEndTime",endTime );
entry.setSearchFoundStartTime(startTime); entry.setSearchFoundStartTime(startTime);

View File

@@ -2,6 +2,9 @@ package com.nis.web.controller.log.ntc;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@@ -20,41 +23,47 @@ import com.google.gson.reflect.TypeToken;
import com.nis.domain.Page; import com.nis.domain.Page;
import com.nis.domain.log.NtcIpLog; import com.nis.domain.log.NtcIpLog;
import com.nis.domain.maat.LogRecvData; import com.nis.domain.maat.LogRecvData;
import com.nis.util.Constants;
import com.nis.util.httpclient.HttpClientUtil;
import com.nis.web.controller.BaseController; import com.nis.web.controller.BaseController;
@Controller @Controller
@RequestMapping("${adminPath}/log/ntc/ip") @RequestMapping("${adminPath}/log/ntc/ip")
public class NtcIpLogController extends BaseController { public class IpLogController extends BaseController {
@RequestMapping("list") @RequestMapping("list")
public String list(@ModelAttribute("log") NtcIpLog log, Model model, HttpServletRequest request, HttpServletResponse response) { public String list(@ModelAttribute("log") NtcIpLog log, Model model, HttpServletRequest request, HttpServletResponse response) {
//初始化action
initLogServiceType(model, log);
Page<NtcIpLog> page = new Page<NtcIpLog>(request, response); Page<NtcIpLog> page = new Page<NtcIpLog>(request, response);
int pageNo = page.getPageNo(); Map<String, Object> params = new HashMap<String, Object>();
params.put("pageSize", page.getPageSize());
params.put("pageNo", page.getPageNo());
initLogSearchValue(log, params);
String url = Constants.LOG_BASE_URL + Constants.NTC_IP_LOG;
String recv = HttpClientUtil.getMsg(url, params);
String recv = null; // try {
// String path = request.getClass().getClassLoader().getResource("").getPath();
try { // recv = FileUtil.readAsString(new File(path + "com/nis/web/test/logTest.txt"));
String path = request.getClass().getClassLoader().getResource("").getPath(); // } catch (IOException e) {
recv = FileUtil.readAsString(new File(path + "com/nis/web/test/logTest.txt")); // e.printStackTrace();
} catch (IOException e) { // }
e.printStackTrace();
}
logger.info("NTC-IP查询结果" + recv);
Gson gson = new GsonBuilder().create(); Gson gson = new GsonBuilder().create();
try { try {
LogRecvData<NtcIpLog> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<NtcIpLog>>(){}.getType()); LogRecvData<NtcIpLog> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<NtcIpLog>>(){}.getType());
if (fromJson.getStatus().intValue() == 200) { if (fromJson.getStatus().intValue() == 200) {
logger.info("查询状态:成功");
BeanUtils.copyProperties(fromJson.getData(), page); BeanUtils.copyProperties(fromJson.getData(), page);
List<NtcIpLog> list = page.getList();
for (NtcIpLog l : list) {
l.setFunctionId(log.getFunctionId());
setLogAction(l);
}
model.addAttribute("page", page); model.addAttribute("page", page);
} }
} catch (JsonSyntaxException e) { } catch (JsonSyntaxException e) {
logger.info("查询失败");
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -2,7 +2,12 @@
<%@ include file="/WEB-INF/include/taglib.jsp"%> <%@ include file="/WEB-INF/include/taglib.jsp"%>
<html> <html>
<head> <head>
<title>IP<spring:message code="log"></spring:message></title> <title>
<c:if test="${log.functionId eq 5 }">IP</c:if>
<c:if test="${log.functionId eq 7 }">DNS</c:if>
<c:if test="${log.functionId eq 8 }">HTTP</c:if>
<spring:message code="log"></spring:message>
</title>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
//reset //reset
@@ -26,7 +31,10 @@
<div class="theme-panel hidden-xs hidden-sm"> <div class="theme-panel hidden-xs hidden-sm">
</div> </div>
<h3 class="page-title"> <h3 class="page-title">
IP<spring:message code="log"></spring:message> <c:if test="${log.functionId eq 5 }">IP</c:if>
<c:if test="${log.functionId eq 7 }">DNS</c:if>
<c:if test="${log.functionId eq 8 }">HTTP</c:if>
<spring:message code="log"></spring:message>
<small><spring:message code="date_list"/></small> <small><spring:message code="date_list"/></small>
</h3> </h3>
<h5 class="page-header"></h5> <h5 class="page-header"></h5>
@@ -35,7 +43,16 @@
<div class="portlet"> <div class="portlet">
<div class="portlet-body"> <div class="portlet-body">
<div class="row" > <div class="row" >
<form:form id="searchForm" modelAttribute="log" action="${ctx}/log/ntc/ip/list" method="post" class="form-search"> <c:if test="${log.functionId eq 5 }">
<c:set var="function" value="ip"/>
</c:if>
<c:if test="${log.functionId eq 7 }">
<c:set var="function" value="dns"/>
</c:if>
<c:if test="${log.functionId eq 8 }">
<c:set var="function" value="http"/>
</c:if>
<form:form id="searchForm" modelAttribute="log" action="${ctx}/log/ntc/${function}/list" method="post" class="form-search">
<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/> <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/> <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
<input id="functionId" name="functionId" type="hidden" value="${log.functionId}"/> <input id="functionId" name="functionId" type="hidden" value="${log.functionId}"/>
@@ -54,9 +71,8 @@
<div class="pull-left"> <div class="pull-left">
<form:select path="serviceType" class="selectpicker select2 input-small"> <form:select path="serviceType" class="selectpicker select2 input-small">
<form:option value=""><spring:message code="action"/></form:option> <form:option value=""><spring:message code="action"/></form:option>
<c:forEach items="${serviceList}" var="service"> <form:option value="16"><spring:message code="action_reject"/></form:option>
<form:option value="${service.serviceId}" ><spring:message code="${service.actionCode}"/></form:option> <form:option value="1"><spring:message code="action_monit"/></form:option>
</c:forEach>
</form:select> </form:select>
</div> </div>
<div class="pull-left"> <div class="pull-left">
@@ -126,12 +142,22 @@
<input name="clientIp" type="text" class="form-control" value="${log.clientIp }"/> <input name="clientIp" type="text" class="form-control" value="${log.clientIp }"/>
</div> </div>
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<div class="form-group"> <div class="form-group">
<label><spring:message code="serverip"></spring:message></label> <label><spring:message code="serverip"></spring:message></label>
<input name="serverIp" type="text" class="form-control" value="${log.serverIp }"/> <input name="serverIp" type="text" class="form-control" value="${log.serverIp }"/>
</div> </div>
</div> </div>
<c:if test="${log.functionId eq 8 }">
<div class="col-md-4">
<div class="form-group">
<label>URL</label>
<input name="url" type="text" class="form-control" value="${log.url }"/>
</div>
</div>
</c:if>
</div> </div>
</div> </div>
<!-- /筛选搜索内容栏 结束--> <!-- /筛选搜索内容栏 结束-->
@@ -142,9 +168,11 @@
<table id="contentTable" class="table table-striped table-bordered table-condensed text-nowrap"> <table id="contentTable" class="table table-striped table-bordered table-condensed text-nowrap">
<thead> <thead>
<tr> <tr>
<th></th>
<!--<th><input type="checkbox" class="i-checks" id="checkAll"></th>--> <!--<th><input type="checkbox" class="i-checks" id="checkAll"></th>-->
<th><spring:message code='cfg_id'/></th> <th><spring:message code='cfg_id'/></th>
<th>ip<spring:message code="type"/></th> <th>ip<spring:message code="type"/></th>
<th><spring:message code="action"/></th>
<th><spring:message code="client_ip"/></th> <th><spring:message code="client_ip"/></th>
<th><spring:message code="client_port"/></th> <th><spring:message code="client_port"/></th>
<th><spring:message code="server_ip"/></th> <th><spring:message code="server_ip"/></th>
@@ -152,6 +180,9 @@
<th><spring:message code="protocol"/></th> <th><spring:message code="protocol"/></th>
<th><spring:message code="entrance_id"/></th> <th><spring:message code="entrance_id"/></th>
<th><spring:message code="direction"/></th> <th><spring:message code="direction"/></th>
<c:if test="${log.functionId eq 8 }">
<th>URL</th>
</c:if>
<th><spring:message code="found_time"/></th> <th><spring:message code="found_time"/></th>
<th><spring:message code="recv_time"/></th> <th><spring:message code="recv_time"/></th>
<th><spring:message code="device_id"/></th> <th><spring:message code="device_id"/></th>
@@ -160,40 +191,48 @@
<th><spring:message code="nest_addr_list"/></th> <th><spring:message code="nest_addr_list"/></th>
<th><spring:message code="user_region"/></th> <th><spring:message code="user_region"/></th>
</tr> </tr>
<c:forEach var="log" items="${page.list }"> <c:forEach var="_log" items="${page.list }">
<tr> <tr>
<td>${log.cfgId }</td> <td></td>
<td>${_log.cfgId }</td>
<td> <td>
<c:forEach items="${fns:getDictList('IP_TYPE')}" var="ipType"> <c:forEach items="${fns:getDictList('IP_TYPE')}" var="ipType">
<c:if test="${ipType.itemCode==log.addrType}">${ipType.itemValue}</c:if> <c:if test="${ipType.itemCode eq _log.addrType}">${ipType.itemValue}</c:if>
</c:forEach> </c:forEach>
</td> </td>
<td>${log.clientIp }</td> <td>
<td>${log.clientPort }</td> <c:if test="${_log.action eq 16 }"><spring:message code="action_reject"/></c:if>
<td>${log.serverIp }</td> <c:if test="${_log.action eq 1 }"><spring:message code="action_monit"/></c:if>
<td>${log.serverPort }</td> </td>
<td>${_log.clientIp }</td>
<td>${_log.clientPort }</td>
<td>${_log.serverIp }</td>
<td>${_log.serverPort }</td>
<td> <td>
<c:forEach items="${fns:getDictList('LOG_PROTOCOL')}" var="logProtocol"> <c:forEach items="${fns:getDictList('LOG_PROTOCOL')}" var="logProtocol">
<c:if test="${logProtocol.itemCode == log.protocol}">${logProtocol.itemValue}</c:if> <c:if test="${logProtocol.itemCode eq _log.protocol}">${logProtocol.itemValue}</c:if>
</c:forEach> </c:forEach>
</td> </td>
<td>${log.entranceId }</td> <td>${_log.entranceId }</td>
<td> <td>
<c:forEach items="${fns:getDictList('DIRECTION')}" var="direction"> <c:forEach items="${fns:getDictList('DIRECTION')}" var="direction">
<c:if test="${direction.itemCode == log.direction}"><spring:message code="${direction.itemValue}"/></c:if> <c:if test="${direction.itemCode eq _log.direction}"><spring:message code="${direction.itemValue}"/></c:if>
</c:forEach> </c:forEach>
</td> </td>
<td>${log.foundTime }</td> <c:if test="${log.functionId eq 8 }">
<td>${log.recvTime }</td> <td title="${_log.url }">${fns:abbr(_log.url, 20)}</td>
<td>${log.deviceId }</td> </c:if>
<td>${_log.foundTime }</td>
<td>${_log.recvTime }</td>
<td>${_log.deviceId }</td>
<td> <td>
<c:forEach items="${fns:getDictList('LOG_STREAM_TYPE')}" var="streamType"> <c:forEach items="${fns:getDictList('LOG_STREAM_TYPE')}" var="streamType">
<c:if test="${streamType.itemCode == log.streamType}">${streamType.itemValue}</c:if> <c:if test="${streamType.itemCode eq _log.streamType}">${streamType.itemValue}</c:if>
</c:forEach> </c:forEach>
</td> </td>
<td>${log.cljIp }</td> <td>${_log.cljIp }</td>
<td>${log.nestAddrList }</td> <td>${_log.nestAddrList }</td>
<td>${log.userRegion }</td> <td>${_log.userRegion }</td>
</tr> </tr>
</c:forEach> </c:forEach>
</thead> </thead>