web.log-view.index.jsp Maven / Gradle / Ivy
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar"
prefix="carbon"%>
<%@ page import="org.wso2.carbon.logging.view.ui.LogViewerClient"%>
<%@ page import="org.apache.axis2.context.ConfigurationContext"%>
<%@ page import="org.wso2.carbon.CarbonConstants"%>
<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogFileInfo"%>
<%-- <%@ page --%>
<%@ page import="org.wso2.carbon.utils.ServerConstants"%>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil"%>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage"%>
<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogFileInfo"%>
<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogEvent"%>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil"%>
<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %>
<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogEvent"%>
<%@ page import="java.util.regex.Matcher"%>
<%@ page import="java.util.regex.Pattern"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.TimeZone" %>
<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogFileInfo" %>
<%@ page import="org.owasp.encoder.Encode" %>
View System Logs
<%!private boolean isArchiveFile(String fileName) {
String archivePattern = "[a-zA-Z]*\\.log";
CharSequence inputStr = fileName;
Pattern pattern = Pattern.compile(archivePattern);
Matcher matcher = pattern.matcher(inputStr);
return matcher.find();
}%>
<%
String backendServerURL = CarbonUIUtil
.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
LogViewerClient logViewerClient;
LogEvent[] events = null;
String type;
String keyword;
String action;
boolean showLogFiles;
String pageNumberStr = request.getParameter("pageNumber");
String pageIndexNumberStr = request.getParameter("pageIndexNumber");
String showMaxStr = request.getParameter("showMax");
int pageNumber = 0;
int pageIndexNumber = 0;
int numberOfIndexPages = 0;
int numberOfPages = 0;
int noOfRows=0;
boolean showMax= false;
boolean isSuperTenant = CarbonUIUtil.isSuperTenant(request);
boolean isManager = false;
String tenantDomain = request.getParameter("tenantDomain");
String serviceName = request.getParameter("serviceName");
String serviceNames[];
LogFileInfo[] logFileInfo = null;
PaginatedLogFileInfo paginatedLogFileInfo = null;
PaginatedLogEvent paginatedLogEvents = null;
String parameter = "";
String indexParameter = "";
boolean isValidTenant = true;
String collapseAdv = request.getParameter("collapse");
boolean isCollapse = Boolean.parseBoolean(collapseAdv);
showMax = Boolean.parseBoolean(showMaxStr);
try {
pageNumber = Integer.parseInt(pageNumberStr);
} catch (NumberFormatException ignored) {
// page number format exception
}
try {
pageIndexNumber = Integer.parseInt(pageIndexNumberStr);
} catch (NumberFormatException ignored) {
// page number format exception
}
try {
type = CharacterEncoder.getSafeText(request.getParameter("type"));
type = (type == null) ? "" : type;
if(tenantDomain == null) {
tenantDomain = "";
}
if (serviceName == null) {
serviceName = "";
}
//tenantDomain = (tenantDomain == null) ? "" : tenantDomain;
keyword = CharacterEncoder.getSafeText(request.getParameter("keyword"));
keyword = (keyword == null) ? "" : keyword;
action = CharacterEncoder.getSafeText(request.getParameter("action"));
logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext);
isValidTenant = logViewerClient.isValidTenant(tenantDomain);
if(isValidTenant) {
paginatedLogEvents = logViewerClient.getPaginatedLogEvents(pageNumber, type,
keyword, tenantDomain, serviceName);
paginatedLogFileInfo = logViewerClient.getLocalLogFiles(pageIndexNumber, tenantDomain, serviceName);
}
if (paginatedLogEvents != null) {
noOfRows = paginatedLogEvents.getNumberOfPages() * 15;
events = paginatedLogEvents.getLogInfo();
numberOfPages = paginatedLogEvents.getNumberOfPages();
}
if (paginatedLogFileInfo != null) {
logFileInfo = paginatedLogFileInfo.getLogFileInfo();
numberOfIndexPages = paginatedLogFileInfo.getNumberOfPages();
}
isManager = logViewerClient.isManager();
serviceNames = logViewerClient.getServiceNames();
showLogFiles = (logFileInfo != null);
if(isManager) {
if(isSuperTenant) {
parameter = "type=" + type + "&keyword=" + keyword + "&serviceName=" + serviceName +
"&tenantDomain=" + tenantDomain + "&collapse=" + isCollapse;
indexParameter = "type=" + type + "&keyword=" + keyword+"&showMax=" + true + "&serviceName=" + serviceName +
"&tenantDomain=" + tenantDomain + "&collapse=" + isCollapse;
} else {
parameter = "type=" + type + "&keyword=" + keyword + "&serviceName=" + serviceName +
"&collapse=" + isCollapse;
indexParameter = "type=" + type + "&keyword=" + keyword+"&showMax=" + true + "&serviceName=" + serviceName +
"&collapse=" + isCollapse;
}
} else {
parameter = "type=" + type + "&keyword=" + keyword;
indexParameter = "type=" + type + "&keyword=" + keyword+"&showMax=" + true;
}
} catch (Exception e) {
CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request,
e);
%>
<%
return;
}
%>
<%
if (isManager) {
%>
<%
if(isCollapse) {
%>
<%
} else {
%>
<%
} else {
%>
<%
}
if (noOfRows > 40000) {
%>
Maximum log limit exceeded!!!.
We only list 40 000 logs through the log viewer(your latest logs will be omitted in the log display), Please download the daily archived logs, for the full log report.
<%
}
%>
<%
if(!isValidTenant) { %>
<%} else {
if (events == null || events.length == 0 || events[0] == null) {
%>
<%
} else {
int index = 0;
for (LogEvent logMessage : events) {
index++;
if (index % 2 != 0) {
%>
<%
} else {
%>
<%
}
%>
<%=logMessage.getLogTime()%>
<%=CharacterEncoder.getSafeText(logMessage.getMessage())%>
<%
String imgId = "traceSymbolMax" + index;
%>
<%
String id = "traceTable" + index;
if (index % 2 != 0) {
%>
<%
}
}
}
%>
<%
if (showLogFiles) {
%>
<%
if(showMax) {
%>
<%
} else {
%>
<%
}
%>
">
<%
int index = -1;
for (LogFileInfo logMessage : logFileInfo) {
++index;
if (index % 2 != 0) {
%>
<%
} else {
%>
<%
}
if (logMessage.getLogName().trim().equalsIgnoreCase("NO_LOG_FILES")) {
%>
<%
} else {
String logFile = logMessage.getLogName();
String logDate = logMessage.getLogDate();
String logSize = logMessage.getFileSize();
%>
<%=logFile%>
<%=logDate%>
<%=logSize%>
<%
if (isArchiveFile(logFile)) {
%>
<%
} else {
%>
<%
}
%>
<%
}
%>
<%
}
%>
<%
}
%>