Started implementing data maintenance function to clean old data from logstream sources

This commit is contained in:
Andre Lorbach 2008-11-11 17:49:53 +01:00
parent c516c72391
commit f22e3019ca
7 changed files with 255 additions and 2 deletions

View File

@ -290,9 +290,57 @@ if ( isset($_GET['op']) )
}
else
{
// Include LogStream facility
include($gl_root_path . 'classes/logstream.class.php');
// --- Init the source
$tmpSource = $content['Sources'][ $content['SOURCEID'] ];
// Copy some default properties
$content['DisplayName'] = $tmpSource['Name'];
$content['SourceType'] = $tmpSource['SourceType'];
CreateSourceTypesList($content['SourceType']);
$content['SourceTypeName'] = $content['SOURCETYPES'][ $content['SourceType'] ]['DisplayName'];
// Fix Filename manually for FILE LOGSTREAM!
if ( $content['SourceType'] == SOURCE_DB || $content['SourceType'] == SOURCE_PDO )
{
// Create LogStream Object
$stream = $tmpSource['ObjRef']->LogStreamFactory($tmpSource['ObjRef']);
$res = $stream->Verify();
if ( $res != SUCCESS )
{
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_WITHINSOURCE'], $tmpSource['Name'], GetErrorMessage($res) );
if ( isset($extraErrorDescription) )
$content['ERROR_MSG'] .= "<br><br>" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription);
}
else
{
// Display Stats
$content['ISCLEARDATA'] = true;
// Gather Database Stats
$content['ROWCOUNT'] = $stream->GetLogStreamTotalRowCount();
if ( isset($content['ROWCOUNT']) )
{
// Allow Deleting by Date
$content['DELETE_ALLOWDETAIL'] = true;
// Create Lists
CreateOlderThanList( 3600 );
CreateOlderDateFields();
}
else
$content['ROWCOUNT'] = "Unknown";
}
}
else
{
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_NOCLEARSUPPORT'], $content['SOURCEID'] );
}
}
}
else if ($_GET['op'] == "dbstats")
@ -347,6 +395,7 @@ if ( isset($_GET['op']) )
$content['STATS'] = $stream->GetLogStreamStats();
if ( isset($content['STATS']) )
{
// Display Stats
$content['ISSTATS'] = true;
foreach( $content['STATS'] as &$myStats )
@ -791,6 +840,65 @@ function ReadMsgParserList()
{
global $gl_root_path, $content;
}
/*
* Helper function to create a OlderThan Listbox
*/
function CreateOlderThanList( $nDefaultSeconds )
{
global $content;
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "1 minute", 'OlderThanSeconds' => 60 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "5 minutes", 'OlderThanSeconds' => 300 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "15 minutes", 'OlderThanSeconds' => 900 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "30 minutes", 'OlderThanSeconds' => 1800 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "1 hour", 'OlderThanSeconds' => 3600 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "12 hours", 'OlderThanSeconds' => 43200 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "1 day", 'OlderThanSeconds' => 86400 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "7 days", 'OlderThanSeconds' => 604800 );
$content['OLDERTHAN'][] = array( 'OlderThanDisplayName' => "31 days", 'OlderThanSeconds' => 2678400 );
foreach ( $content['OLDERTHAN'] as &$myTime )
{
if ( $nDefaultSeconds == $myTime['OlderThanSeconds'] )
$myTime['selected'] = "selected";
else
$myTime['selected'] = "";
}
}
/*
* Helper function to create a OlderThan Listbox
*/
function CreateOlderDateFields()
{
global $content;
$currentTime = time();
$currentDay = date("d", $currentTime);
$currentMonth = date("m", $currentTime);
$currentYear = date("Y", $currentTime);
// Init Year, month and day array!
for ( $i = $currentYear-5; $i <= $currentYear+5; $i++ )
{
$content['olderdate_years'][$i]['value'] = $i;
if ( $i == $currentYear ) { $content['olderdate_years'][$i]['selected'] = "selected"; } else { $content['olderdate_years'][$i]['selected'] = ""; }
}
for ( $i = 1; $i <= 12; $i++ )
{
$content['olderdate_months'][$i]['value'] = $i;
if ( $i == $currentMonth ) { $content['olderdate_months'][$i]['selected'] = "selected"; } else { $content['olderdate_months'][$i]['selected'] = ""; }
}
for ( $i = 1; $i <= 31; $i++ )
{
$content['olderdate_days'][$i]['value'] = $i;
if ( $i == $currentDay ) { $content['olderdate_days'][$i]['selected'] = "selected"; } else { $content['olderdate_days'][$i]['selected'] = ""; }
}
}
// --- END Custom Code
// --- BEGIN CREATE TITLE

View File

@ -219,6 +219,11 @@ abstract class LogStream {
public abstract function GetLogStreamStats();
/**
* This returns just the count of records of the main data source
*/
public abstract function GetLogStreamTotalRowCount();
/*
* Helper functino to trigger initialisation of MsgParsers
*/

View File

@ -597,6 +597,44 @@ class LogStreamDB extends LogStream {
}
/**
* Implementation of GetLogStreamTotalRowCount
*
* Returns the total amount of rows in the main datatable
*/
public function GetLogStreamTotalRowCount()
{
global $querycount, $dbmapping;
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Set default rowcount
$rowcount = null;
// Perform if Connection is true!
if ( $this->_dbhandle != null )
{
// SHOW TABLE STATUS FROM
$szSql = "SELECT count(" . $dbmapping[$szTableType][SYSLOG_UID] . ") as Counter FROM " . $this->_logStreamConfigObj->DBTableName;
$myQuery = mysql_query($szSql, $this->_dbhandle);
if ($myQuery)
{
// Obtain RowCount!
$myRow = mysql_fetch_row($myQuery);
$rowcount = $myRow[0];
// Free query now
mysql_free_result ($myQuery);
// Increment for the Footer Stats
$querycount++;
}
}
//return result
return $rowcount;
}
/**
* Implementation of GetCountSortedByField
*

View File

@ -235,6 +235,12 @@ $content['LN_SOURCES_STATSVALUE'] = "Value";
$content['LN_SOURCES_DETAILS'] = "Details for this logstream source";
$content['LN_SOURCES_STATSDETAILS'] = "Statistic details for this logstream source";
$content['LN_SOURCES_ERROR_NOSTATSDATA'] = "Could not find or obtain any stats related information for this logstream source.";
$content['LN_SOURCES_ERROR_NOCLEARSUPPORT'] = "This logstream source does not support deleting data.";
$content['LN_SOURCES_ROWCOUNT'] = "Total Rowcount";
$content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting data, any action performed here can not be undone!";
$content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... ";
$content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... ";
$content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range";
// Database Upgrade
$content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update";

View File

@ -237,7 +237,15 @@ $content['LN_SOURCES_STATSVALUE'] = "Value";
$content['LN_SOURCES_DETAILS'] = "Details for this logstream source";
$content['LN_SOURCES_STATSDETAILS'] = "Statistic details for this logstream source";
$content['LN_SOURCES_ERROR_NOSTATSDATA'] = "Could not find or obtain any stats related information for this logstream source.";
$content['LN_SOURCES_ERROR_NOCLEARSUPPORT'] = "This logstream source does not support deleting data.";
$content['LN_SOURCES_ROWCOUNT'] = "Total Rowcount";
$content['LN_SOURCES_CLEARDATA'] = "The following database maintenance Options are available";
$content['LN_SOURCES_CLEAROPTIONS'] = "Select how you want to clear data.";
$content['LN_SOURCES_CLEARALL'] = "Clear (Delete) all data.";
$content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting data, any action performed here can not be undone!";
$content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... ";
$content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... ";
$content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range";
// Database Upgrade
$content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update";

View File

@ -235,6 +235,12 @@ $content['LN_SOURCES_STATSVALUE'] = "Value";
$content['LN_SOURCES_DETAILS'] = "Details for this logstream source";
$content['LN_SOURCES_STATSDETAILS'] = "Statistic details for this logstream source";
$content['LN_SOURCES_ERROR_NOSTATSDATA'] = "Could not find or obtain any stats related information for this logstream source.";
$content['LN_SOURCES_ERROR_NOCLEARSUPPORT'] = "This logstream source does not support deleting data.";
$content['LN_SOURCES_ROWCOUNT'] = "Total Rowcount";
$content['LN_SOURCES_CLEAR_HELPTEXT'] = "Attention! Be carefull with deleting data, any action performed here can not be undone!";
$content['LN_SOURCES_CLEARSINCE'] = "Clear all data older than ... ";
$content['LN_SOURCES_CLEARDATE'] = "Clear all data which is older than ... ";
$content['LN_SOURCES_CLEARDATA_SEND'] = "Clear selected data range";
// Database Upgrade
$content['LN_DBUPGRADE_TITLE'] = "phpLogCon Database Update";

View File

@ -100,8 +100,90 @@
</table>
<!-- ENDIF LISTSOURCES="true" -->
<!-- IF ISSTATS="true" -->
<!-- IF ISCLEARDATA="true" -->
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#DDDDDD" width="600" class="with_border_alternate">
<tr>
<td align="center" class="cellmenu1" colspan="2"><b>{LN_SOURCES_DETAILS}</b></td>
</tr>
<tr>
<td align="left" class="cellmenu2" width="200"><b>{LN_SOURCES_ID}</b></td>
<td align="left" class="line1" width="400">{SOURCEID}</td>
</tr>
<tr>
<td align="left" class="cellmenu2"><b>{LN_SOURCES_NAME}</b></td>
<td align="left" class="line2">{DisplayName}</td>
</tr>
<tr>
<td align="left" class="cellmenu2" valign="top"><b>{LN_SOURCES_TYPE}</b></td>
<td align="left" class="line1">{SourceTypeName}</td>
</tr>
<tr>
<td align="left" class="cellmenu2" valign="top"><b>{LN_SOURCES_ROWCOUNT}</b></td>
<td align="left" class="line1">{ROWCOUNT}</td>
</tr>
</table>
<br />
<form action="{BASEPATH}admin/sources.php?op=cleardata&id={SOURCEID}" method="post">
<table border="0" cellpadding="2" cellspacing="1" bgcolor="#DDDDDD" width="600" class="with_border_alternate">
<tr>
<td align="center" class="cellmenu1" nowrap colspan="2"><B>{LN_SOURCES_CLEARDATA}</B></td>
</tr>
<tr>
<td class="titleSecond" colspan="2"><blockquote>{LN_SOURCES_CLEAR_HELPTEXT}</blockquote></td>
</tr>
<tr>
<td align="left" class="cellmenu2_naked" width="200" valign="top"><b>{LN_SOURCES_CLEAROPTIONS}</b></td>
<td align="left" class="line1" width="400">
<br>
<input type="radio" name="subop" value="all">&nbsp;&nbsp;<b>{LN_SOURCES_CLEARALL}</b><br>
<!-- IF DELETE_ALLOWDETAIL="true" -->
<input type="radio" name="subop" value="since">&nbsp;&nbsp;<b>{LN_SOURCES_CLEARSINCE}</b>
<select name="olderthan" size="1">
<!-- BEGIN OLDERTHAN -->
<option {selected} value="{OlderThanSeconds}">{OlderThanDisplayName}</option>
<!-- END OLDERTHAN -->
</select>
<br>
<input type="radio" name="subop" value="date">&nbsp;&nbsp;<b>{LN_SOURCES_CLEARDATE}</b>
<select name="olderdate_year" size="1">
<!-- BEGIN olderdate_years -->
<option {selected} value="{value}">{value}</option>
<!-- END olderdate_years -->
</select>
-
<select name="olderdate_from_month" size="1">
<!-- BEGIN olderdate_months -->
<option {selected} value="{value}">{value}</option>
<!-- END olderdate_months -->
</select>
-
<select name="olderdate_from_day" size="1">
<!-- BEGIN olderdate_days -->
<option {selected} value="{value}">{value}</option>
<!-- END olderdate_days -->
</select>
<br>
<br>
<!-- ENDIF DELETE_ALLOWDETAIL="true" -->
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="{LN_SOURCES_CLEARDATA_SEND}">
</td>
</tr>
</table>
</form>
<br><br>
<a href="javascript:history.back();" target="_top">{LN_GEN_ERRORRETURNPREV}</a>
<!-- ENDIF ISCLEARDATA="true" -->
<!-- IF ISSTATS="true" -->
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#DDDDDD" width="500" class="with_border_alternate">
<tr>
<td align="center" class="cellmenu1" colspan="2"><b>{LN_SOURCES_DETAILS}</b></td>