Commit 29b2054a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support to rollover by date and total max size. JM-298

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3709 b35dd754-fafc-0310-a699-88a17e54d16e
parent b7cf0726
......@@ -54,6 +54,24 @@ public interface AuditManager {
*/
Auditor getAuditor();
/**
* Returns the maximum size in megabytes that all audit log files may have. When the
* limit is reached oldest audit log files will be removed until total size is under
* the limit.
*
* @return the maximum size of all audit logs in megabytes.
*/
int getMaxTotalSize();
/**
* Sets the maximum size in megabytes that all audit log files may have. When the
* limit is reached oldest audit log files will be removed until total size is under
* the limit.
*
* @param size the maximum size of all audit logs in megabytes.
*/
void setMaxTotalSize(int size);
/**
* Obtain the maximum size of audit log files in megabytes.
* Logs that exceed the max size will be rolled over to another
......@@ -71,23 +89,22 @@ public interface AuditManager {
void setMaxFileSize(int size);
/**
* Obtain the maximum number of audit files to create. Audit files that
* exceed the maximum file size will be rolled over to new files.
* If there are more log files than the max file count, then the
* oldest log file is overwritten.
* Returns the maximum number of days to keep audit information. Once the limit
* has been reached audit files that contain information that exceed the limit
* will be deleted.
*
* @return the maximum number of audit files that will be created
* @return the maximum number of days to keep audit information
* or -1 for unlimited
*/
int getMaxFileCount();
int getMaxDays();
/**
* Set the maximum number of audit files to create.
* Set the the maximum number of days to keep audit information.
*
* @param count the maximum number of audit files that will be
* created or -1 for unlimited
* @param count the maximum number of days to keep audit information
* or -1 for unlimited
*/
void setMaxFileCount(int count);
void setMaxDays(int count);
/**
* Returns the time in milliseconds between successive executions of the task that will save
......
......@@ -11,6 +11,7 @@
package org.jivesoftware.wildfire.audit.spi;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.Session;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.audit.AuditManager;
......@@ -18,9 +19,8 @@ import org.jivesoftware.wildfire.audit.Auditor;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.interceptor.InterceptorManager;
import org.jivesoftware.wildfire.interceptor.PacketInterceptor;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.Packet;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import java.io.File;
import java.util.*;
......@@ -37,13 +37,27 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
private boolean auditXPath;
private List xpath = new LinkedList();
private AuditorImpl auditor = null;
private int maxSize;
private int maxCount;
/**
* Max size in bytes that all audit log files may have. When the limit is reached
* oldest audit log files will be removed until total size is under the limit.
*/
private int maxTotalSize;
/**
* Max size in bytes that each audit log file may have. Once the limit has been
* reached a new audit file will be created.
*/
private int maxFileSize;
/**
* Max number of days to keep audit information. Once the limit has been reached
* audit files that contain information that exceed the limit will be deleted.
*/
private int maxDays;
private int logTimeout;
private String logDir;
private Collection<String> ignoreList = new ArrayList<String>();
private static final int MAX_TOTAL_SIZE = 1000;
private static final int MAX_FILE_SIZE = 10;
private static final int MAX_FILE_COUNT = 10;
private static final int MAX_DAYS = -1;
private static final int DEFAULT_LOG_TIMEOUT = 120000;
private AuditorInterceptor interceptor;
......@@ -74,14 +88,40 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
return auditor;
}
public int getMaxTotalSize() {
return maxTotalSize;
}
public void setMaxTotalSize(int size) {
maxTotalSize = size;
auditor.setMaxValues(maxTotalSize, maxFileSize, maxDays);
JiveGlobals.setProperty("xmpp.audit.totalsize", Integer.toString(size));
}
public int getMaxFileSize() {
return maxSize;
return maxFileSize;
}
public void setMaxFileSize(int size) {
maxSize = size;
auditor.setMaxValues(maxSize, maxCount);
JiveGlobals.setProperty("xmpp.audit.maxsize", Integer.toString(size));
maxFileSize = size;
auditor.setMaxValues(maxTotalSize, maxFileSize, maxDays);
JiveGlobals.setProperty("xmpp.audit.filesize", Integer.toString(size));
}
public int getMaxDays() {
return maxDays;
}
public void setMaxDays(int count) {
if (count < -1) {
count = -1;
}
if (count == 0) {
count = 1;
}
maxDays = count;
auditor.setMaxValues(maxTotalSize, maxFileSize, maxDays);
JiveGlobals.setProperty("xmpp.audit.days", Integer.toString(count));
}
public int getLogTimeout() {
......@@ -104,16 +144,6 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
JiveGlobals.setProperty("xmpp.audit.logdir", logDir);
}
public int getMaxFileCount() {
return maxCount;
}
public void setMaxFileCount(int count) {
maxCount = count;
auditor.setMaxValues(maxSize, maxCount);
JiveGlobals.setProperty("xmpp.audit.maxcount", Integer.toString(count));
}
public boolean isAuditMessage() {
return auditMessage;
}
......@@ -208,8 +238,9 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
// for (int i = 0; i < filters.length; i++) {
// xpath.add(filters[i]);
// }
maxSize = JiveGlobals.getIntProperty("xmpp.audit.maxsize", MAX_FILE_SIZE);
maxCount = JiveGlobals.getIntProperty("xmpp.audit.maxcount", MAX_FILE_COUNT);
maxTotalSize = JiveGlobals.getIntProperty("xmpp.audit.totalsize", MAX_TOTAL_SIZE);
maxFileSize = JiveGlobals.getIntProperty("xmpp.audit.filesize", MAX_FILE_SIZE);
maxDays = JiveGlobals.getIntProperty("xmpp.audit.days", MAX_DAYS);
logTimeout = JiveGlobals.getIntProperty("xmpp.audit.logtimeout", DEFAULT_LOG_TIMEOUT);
logDir = JiveGlobals.getProperty("xmpp.audit.logdir", JiveGlobals.getHomeDirectory() +
File.separator + "logs");
......@@ -222,9 +253,9 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
}
auditor = new AuditorImpl(this);
auditor.setMaxValues(maxSize, maxCount);
auditor.setLogTimeout(logTimeout);
auditor.setMaxValues(maxTotalSize, maxFileSize, maxDays);
auditor.setLogDir(logDir);
auditor.setLogTimeout(logTimeout);
interceptor = new AuditorInterceptor();
if (enabled) {
......
......@@ -9,16 +9,15 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.wildfire.audit.AuditManager,
org.jivesoftware.util.*,
java.util.*,
java.io.File,
<%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.wildfire.XMPPServer,
org.jivesoftware.wildfire.audit.AuditManager,
org.jivesoftware.wildfire.user.UserNotFoundException,
org.xmpp.packet.JID,
org.jivesoftware.wildfire.user.UserNotFoundException"
java.io.File"
errorPage="error.jsp"
%>
<%@ page import="org.jivesoftware.wildfire.XMPPServer"%>
<%@ page import="org.jivesoftware.wildfire.user.UserManager"%>
<%@ page import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
......@@ -44,8 +43,9 @@
boolean auditXPath = ParamUtils.getBooleanParameter(request,"auditXPath");
String newXpathQuery = ParamUtils.getParameter(request,"newXpathQuery");
String[] xpathQuery = ParamUtils.getParameters(request,"xpathQuery");
String maxCount = ParamUtils.getParameter(request,"maxCount");
String maxSize = ParamUtils.getParameter(request,"maxSize");
String maxTotalSize = ParamUtils.getParameter(request,"maxTotalSize");
String maxFileSize = ParamUtils.getParameter(request,"maxFileSize");
String maxDays = ParamUtils.getParameter(request,"maxDays");
String logTimeout = ParamUtils.getParameter(request,"logTimeout");
String logDir = ParamUtils.getParameter(request,"logDir");
String ignore = ParamUtils.getParameter(request,"ignore");
......@@ -70,14 +70,19 @@
}
*/
try {
auditManager.setMaxFileCount(Integer.parseInt(maxCount));
auditManager.setMaxTotalSize(Integer.parseInt(maxTotalSize));
} catch (Exception e){
errors.put("maxCount","maxCount");
errors.put("maxTotalSize","maxTotalSize");
}
try {
auditManager.setMaxFileSize(Integer.parseInt(maxSize));
auditManager.setMaxFileSize(Integer.parseInt(maxFileSize));
} catch (Exception e){
errors.put("maxSize","maxSize");
errors.put("maxFileSize","maxFileSize");
}
try {
auditManager.setMaxDays(Integer.parseInt(maxDays));
} catch (Exception e){
errors.put("maxDays","maxDays");
}
try {
auditManager.setLogTimeout(Integer.parseInt(logTimeout) * 1000);
......@@ -150,8 +155,9 @@
auditPresence = auditManager.isAuditPresence();
auditIQ = auditManager.isAuditIQ();
auditXPath = auditManager.isAuditXPath();
maxCount = Integer.toString(auditManager.getMaxFileCount());
maxSize = Integer.toString(auditManager.getMaxFileSize());
maxTotalSize = Integer.toString(auditManager.getMaxTotalSize());
maxFileSize = Integer.toString(auditManager.getMaxFileSize());
maxDays = Integer.toString(auditManager.getMaxDays());
logTimeout = Integer.toString(auditManager.getLogTimeout() / 1000);
logDir = auditManager.getLogDir();
StringBuilder ignoreList = new StringBuilder();
......@@ -225,15 +231,33 @@
</td>
</tr>
<tr valign="top">
<td width="1%" nowrap class="c1">
<fmt:message key="audit.policy.maxtotal_size" />
</td>
<td width="99%">
<input type="text" size="15" maxlength="50" name="maxTotalSize"
value="<%= ((maxTotalSize != null) ? maxTotalSize : "") %>">
<% if (errors.get("maxTotalSize") != null) { %>
<span class="jive-error-text">
<fmt:message key="audit.policy.validnumber" />
</span>
<% } %>
</td>
</tr>
<tr valign="top">
<td width="1%" nowrap class="c1">
<fmt:message key="audit.policy.maxfile_size" />
</td>
<td width="99%">
<input type="text" size="15" maxlength="50" name="maxSize"
value="<%= ((maxSize != null) ? maxSize : "") %>">
<input type="text" size="15" maxlength="50" name="maxFileSize"
value="<%= ((maxFileSize != null) ? maxFileSize : "") %>">
<% if (errors.get("maxSize") != null) { %>
<% if (errors.get("maxFileSize") != null) { %>
<span class="jive-error-text">
<fmt:message key="audit.policy.validnumber" />
......@@ -245,13 +269,13 @@
</tr>
<tr valign="top">
<td width="1%" nowrap class="c1">
<fmt:message key="audit.policy.maxfile_number" />
<fmt:message key="audit.policy.maxdays_number" />
</td>
<td width="99%">
<input type="text" size="15" maxlength="50" name="maxCount"
value="<%= ((maxCount != null) ? maxCount : "") %>">
<input type="text" size="15" maxlength="50" name="maxDays"
value="<%= ((maxDays != null) ? maxDays : "") %>">
<% if (errors.get("maxCount") != null) { %>
<% if (errors.get("maxDays") != null) { %>
<span class="jive-error-text">
<fmt:message key="audit.policy.validnumber" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment