added support for automtaically adding missing fields into logstreamdb for reports.

Earlier this was only possible on the main loganalyzer index site
This commit is contained in:
Andre Lorbach 2011-11-02 16:16:25 +01:00
parent 911e0f4a70
commit 6b6724ab00
7 changed files with 449 additions and 114 deletions

View File

@ -1256,8 +1256,31 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
// Check if optimize variable is set!
if ( isset($_GET['optimize']) )
{
// Check what we have to do
if ( $_GET['optimize'] == "indexes" )
if ( $_GET['optimize'] == "addfields" )
{
// This will create all INDEXES we need for this logstream!
$res = $myReportObj->CreateMissingLogStreamFields( $mySourceID );
if ( $res != SUCCESS )
{
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_FAILED_ADDING_FIELDS'], $content['SOURCES'][$mySourceID]['Name'], $res );
if ( isset($extraErrorDescription) )
$content['ERROR_MSG'] .= "<br><br>" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription);
}
// Show information in performance warning area
$content['ISSOURCENOTOPTIMIZED'] = true;
$content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_FIELDS_CREATED'];
$content['MSG_WARNING_CLASS'] = 'PriorityNotice';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_FIELDS_CREATED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] );
$content['MSG_WARNING_SUBMITFORM'] = "false";
// return result
return $res;
}
else if ( $_GET['optimize'] == "indexes" )
{
// This will create all INDEXES we need for this logstream!
$res = $myReportObj->CreateLogStreamIndexes( $mySourceID );
@ -1273,7 +1296,7 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
$content['ISSOURCENOTOPTIMIZED'] = true;
$content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_INDEX_CREATED'];
$content['MSG_WARNING_CLASS'] = 'PriorityNotice';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_INDEX_CREATED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] ); // GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_IDNOTFOUND'], $content['ReportID'] );
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_INDEX_CREATED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] );
$content['MSG_WARNING_SUBMITFORM'] = "false";
// return result
@ -1300,6 +1323,30 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
$content['MSG_WARNING_SUBMITFORM'] = "false";
}
// return result
return $res;
}
else if ( $_GET['optimize'] == "checksum" )
{
// This will create all INDEXES we need for this logstream!
$res = $myReportObj->ChangeChecksumFieldUnsigned( $mySourceID );
if ( $res != SUCCESS )
{
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_FAILED_CHANGE_CHECKSUM'], $content['SOURCES'][$mySourceID]['Name'], $res );
if ( isset($extraErrorDescription) )
$content['ERROR_MSG'] .= "<br><br>" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription);
}
else
{
// Show information in performance warning area
$content['ISSOURCENOTOPTIMIZED'] = true;
$content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_CHECKSUM_CHANGED'];
$content['MSG_WARNING_CLASS'] = 'PriorityNotice';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_CHECKSUM_CHANGED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] );
$content['MSG_WARNING_SUBMITFORM'] = "false";
}
// return result
return $res;
}
@ -1317,13 +1364,21 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
// Current Logstream Source is not optimized! Show to user!
$content['ISSOURCENOTOPTIMIZED'] = true;
if ( $res == ERROR_DB_INDEXESMISSING )
if ( $res == ERROR_DB_DBFIELDNOTFOUND )
{
$content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_PERFORMANCE_WARNING'];
$content['MSG_WARNING_CLASS'] = 'PriorityWarning';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_ADD_MISSINGFIELDS'], $content['SOURCES'][$mySourceID]['Name'] ); // GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_IDNOTFOUND'], $content['ReportID'] );
$content['MSG_WARNING_SUBMITFORM'] = "true";
$content['MSG_WARNING_FORMURL'] .= "optimize=addfields"; // Addmissing fields
}
else if ( $res == ERROR_DB_INDEXESMISSING )
{
$content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_PERFORMANCE_WARNING'];
$content['MSG_WARNING_CLASS'] = 'PriorityWarning';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_OPTIMIZE_INDEXES'], $content['SOURCES'][$mySourceID]['Name'] ); // GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_IDNOTFOUND'], $content['ReportID'] );
$content['MSG_WARNING_SUBMITFORM'] = "true";
$content['MSG_WARNING_FORMURL'] .= "optimize=indexes"; // Optimize INDEXES in this case!
$content['MSG_WARNING_FORMURL'] .= "optimize=indexes"; // Add missing INDEXES
}
else if ( $res == ERROR_DB_TRIGGERMISSING )
{
@ -1331,7 +1386,15 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID)
$content['MSG_WARNING_CLASS'] = 'PriorityWarning';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_OPTIMIZE_TRIGGER'], $content['SOURCES'][$mySourceID]['Name'] ); // GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_IDNOTFOUND'], $content['ReportID'] );
$content['MSG_WARNING_SUBMITFORM'] = "true";
$content['MSG_WARNING_FORMURL'] .= "optimize=trigger"; // Optimize INDEXES in this case!
$content['MSG_WARNING_FORMURL'] .= "optimize=trigger"; // Add missing TRIGGERS
}
else if ( $res == ERROR_DB_CHECKSUMERROR )
{
$content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_PERFORMANCE_WARNING'];
$content['MSG_WARNING_CLASS'] = 'PriorityWarning';
$content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_CHANGE_CHECKSUM'], $content['SOURCES'][$mySourceID]['Name'] ); // GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_IDNOTFOUND'], $content['ReportID'] );
$content['MSG_WARNING_SUBMITFORM'] = "true";
$content['MSG_WARNING_FORMURL'] .= "optimize=checksum"; // Change Checksum field!
}
}
}

View File

@ -264,6 +264,18 @@ abstract class LogStream {
public abstract function ResetFilters( );
/*
* Helper function for logstream classes to check if all fields are available!
*/
public abstract function VerifyFields( $arrProperitesIn );
/*
* Helper function for logstream classes to create missing indexes, only applies to database based logstream classes
*/
public abstract function CreateMissingFields( $arrProperitesIn );
/*
* Helper function for logstream classes to check for data indexes, only applies to database based logstream classes
*/
@ -288,6 +300,23 @@ abstract class LogStream {
public abstract function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty );
/*
* Helper function for logstream classes to create the SQL statement needed to create the trigger, only applies to database based logstream classes
*/
public abstract function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField );
/*
* Helper function for logstream classes to check if the checksum field is configured correctly
*/
public abstract function VerifyChecksumField( );
/*
* Helper function for logstream classes to change the checksum field from unsigned INT
*/
public abstract function ChangeChecksumFieldUnsigned( );
/*
* Helper functino to trigger initialisation of MsgParsers
*/

View File

@ -182,6 +182,39 @@ class LogStreamDB extends LogStream {
}
/*
* Implementation of VerifyFields: Checks if fields exist in table
*/
public function VerifyFields( $arrProperitesIn )
{
global $dbmapping, $fields;
// Get List of Indexes as Array
$arrFieldKeys = $this->GetFieldsAsArray();
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Loop through all fields to see which one is missing!
foreach ( $arrProperitesIn as $myproperty )
{
// echo $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "<br>";
if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrFieldKeys) )
{
OutputDebugMessage("LogStreamDB|VerifyFields: Found Field for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG);
continue;
}
else
{
// Index is missing for this field!
OutputDebugMessage("LogStreamDB|VerifyFields: Missing Field for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_WARN);
return ERROR_DB_DBFIELDNOTFOUND;
}
}
// Successfull
return SUCCESS;
}
/*
* Implementation of VerifyIndexes: Checks if indexes exist for desired fields
*/
@ -295,29 +328,83 @@ class LogStreamDB extends LogStream {
/*
* Implementation of CreateMissingTrigger: Checks if indexes exist for desired fields
* Implementation of CreateMissingFields: Checks if indexes exist for desired fields
*/
public function CreateMissingFields( $arrProperitesIn )
{
global $dbmapping, $fields, $querycount;
// Get List of Indexes as Array
$arrFieldKeys = $this->GetFieldsAsArray();
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Loop through all fields to see which one is missing!
foreach ( $arrProperitesIn as $myproperty )
{
if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrFieldKeys) )
continue;
else
{
if ( $this->HandleMissingField( $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrProperitesIn ) == SUCCESS )
{
// Index is missing for this field!
OutputDebugMessage("LogStreamDB|CreateMissingFields: Createing missing FIELD for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], DEBUG_INFO);
}
else
{
// Return failure!
$this->PrintDebugError("Dynamically Adding FIELD for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' failed!");
return ERROR_DB_ADDDBFIELDFAILED;
}
}
}
// Successfull
return SUCCESS;
}
/*
* Implementation of GetCreateMissingTriggerSQL: Creates SQL needed to create a TRIGGER
*/
public function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField )
{
global $dbmapping, $fields, $querycount;
// Get List of Triggers as Array
$szDBName = $this->_logStreamConfigObj->DBName;
$szTableName = $this->_logStreamConfigObj->DBTableName;
// Create Triggername
$szTriggerName = $szDBName . "_" . $szTableName . "_" . $myDBTriggerField;
// Create TRIGGER SQL!
$szSql = "CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT ON `" . $szTableName . "`
FOR EACH ROW
BEGIN
SET NEW." . $myDBTriggerCheckSumField . " = crc32(NEW." . $myDBTriggerField . ");
END
;";
return $szSql;
}
/*
* Implementation of CreateMissingTrigger: Creates missing triggers !
*/
public function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty )
{
global $dbmapping, $fields, $querycount;
// Get List of Triggers as Array
$szDBName = $this->_logStreamConfigObj->DBName;
$szTableType = $this->_logStreamConfigObj->DBTableType;
$szTableName = $this->_logStreamConfigObj->DBTableName;
$szTableType = $this->_logStreamConfigObj->DBTableType;
$szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty];
$szDBTriggerCheckSumField = $dbmapping[$szTableType]['DBMAPPINGS'][$myCheckSumProperty];
// Create Triggername
$szTriggerName = $szDBName . "_" . $szTableName . "_" . $szDBTriggerField;
// Create TRIGGER SQL!
$szSql = "CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT ON `" . $szTableName . "`
FOR EACH ROW
BEGIN
SET NEW." . $szDBTriggerCheckSumField . " = crc32(NEW." . $szDBTriggerField . ");
END
;";
// Get SQL Code to create the trigger!
$szSql = $this->GetCreateMissingTriggerSQL( $szDBTriggerField, $szDBTriggerCheckSumField );
// Index is missing for this field!
OutputDebugMessage("LogStreamDB|CreateMissingTrigger: Creating missing TRIGGER for '" . $szTableName . "' - $szDBTriggerCheckSumField = crc32(NEW.$szDBTriggerField)" . $szSql, DEBUG_INFO);
@ -327,7 +414,8 @@ class LogStreamDB extends LogStream {
if (!$myQuery)
{
// Return failure!
$this->PrintDebugError("Dynamically Adding TRIGGER for '" . $szTableName . "' failed with Statement: '" . $szSql . "'");
$this->PrintDebugError("Dynamically Adding TRIGGER for '" . $szTableName . "' failed!<br/><br/>If you want to manually add the TRIGGER, use the following SQL Command:<br/> " . str_replace("\n", "<br/>", $szSql) . "<br/>");
return ERROR_DB_TRIGGERFAILED;
}
@ -336,6 +424,70 @@ class LogStreamDB extends LogStream {
}
/*
* Implementation of ChangeChecksumFieldUnsigned: Changes the Checkusm field to unsigned!
*/
public function ChangeChecksumFieldUnsigned()
{
global $dbmapping, $fields, $querycount;
// Get variables
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Change Checksumfield to use UNSIGNED!
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` CHANGE `" .
$dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "` `" .
$dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "` INT(11) UNSIGNED NOT NULL DEFAULT '0'";
// Update Table schema now!
$myQuery = mysql_query($szUpdateSql, $this->_dbhandle);
if (!$myQuery)
{
// Return failure!
$this->PrintDebugError("ER_BAD_FIELD_ERROR - Failed to Change field '" . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "' from signed to unsigned with sql statement: '" . $szUpdateSql . "'");
return ERROR_DB_CHECKSUMCHANGEFAILED;
}
// return results
return SUCCESS;
}
/*
* Implementation of VerifyChecksumField: Verifies if the checkusm field is signed or unsigned!
*/
public function VerifyChecksumField()
{
global $dbmapping, $fields, $querycount;
// Get variables
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Create SQL and Get INDEXES for table!
$szSql = "SHOW COLUMNS FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE Field = '" . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "'";
$myQuery = mysql_query($szSql, $this->_dbhandle);
if ($myQuery)
{
// Get result!
$myRow = mysql_fetch_array($myQuery, MYSQL_ASSOC);
if (strpos( strtolower($myRow['Type']), "unsigned") === false )
{
// return error code!
return ERROR_DB_CHECKSUMERROR;
}
// Free query now
mysql_free_result ($myQuery);
// Increment for the Footer Stats
$querycount++;
}
// return results
return SUCCESS;
}
/**
* Read the data from a specific uID which means in this
* case beginning with from the Database ID
@ -770,7 +922,7 @@ class LogStreamDB extends LogStream {
// UPDATE DATA NOW!
$szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName .
" SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = crc32(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_MESSAGE] . ") " .
" WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL";
" WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL OR " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = 0";
// Output Debug Informations
OutputDebugMessage("LogStreamDB|UpdateAllMessageChecksum: Running Created SQL Query:<br>" . $szSql, DEBUG_ULTRADEBUG);
@ -1687,63 +1839,73 @@ class LogStreamDB extends LogStream {
/*
* Function handles missing database fields automatically!
*/
private function HandleMissingField()
private function HandleMissingField( $szMissingField = null, $arrProperties = null )
{
global $dbmapping, $fields;
// Get Err description
$errdesc = mysql_error();
// check matching of error msg!
if ( preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc, $errOutArr ) )
// Try to get missing field from SQL Error of not specified as argument
if ( $szMissingField == null )
{
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Loop through all fields to see which one is missing!
foreach ( $this->_arrProperties as $myproperty )
if ( preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc, $errOutArr ) )
$szMissingField = $errOutArr[1];
else
{
if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && $errOutArr[1] == $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] )
{
// Create SQL Numeric field
$szUpdateSql = ""; $szUnsigned = "";
if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER )
{
// This will add the checksum field as unsigned automatically!
if ( $myproperty == MISC_CHECKSUM )
$szUnsigned = "UNSIGNED";
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) " . $szUnsigned . " NOT NULL DEFAULT '0'";
}
if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING )
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` varchar(60) NOT NULL DEFAULT ''";
if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE )
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'";
$this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc);
return ERROR_DB_DBFIELDNOTFOUND;
}
}
if ( strlen($szUpdateSql) > 0 )
{
// Update Table schema now!
$myQuery = mysql_query($szUpdateSql, $this->_dbhandle);
if (!$myQuery)
{
// Return failure!
$this->PrintDebugError("ER_BAD_FIELD_ERROR - Dynamically Adding field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' with Statement failed: '" . $szUpdateSql . "'");
return ERROR_DB_DBFIELDNOTFOUND;
}
}
else
// Set Properties to default if NULL
if ( $arrProperties == null )
$arrProperties = $this->_arrProperties;
// Get Tabletype
$szTableType = $this->_logStreamConfigObj->DBTableType;
// Loop through all fields to see which one is missing!
foreach ( $arrProperties as $myproperty )
{
if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && $szMissingField == $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] )
{
// Create SQL Numeric field
$szUpdateSql = ""; $szUnsigned = "";
if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER )
{
// This will add the checksum field as unsigned automatically!
if ( $myproperty == MISC_CHECKSUM )
$szUnsigned = "UNSIGNED";
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) " . $szUnsigned . " NOT NULL DEFAULT '0'";
}
if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING )
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` varchar(60) NOT NULL DEFAULT ''";
if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE )
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'";
if ( strlen($szUpdateSql) > 0 )
{
// Update Table schema now!
$myQuery = mysql_query($szUpdateSql, $this->_dbhandle);
if (!$myQuery)
{
// Return failure!
$this->PrintDebugError("ER_BAD_FIELD_ERROR - Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' is missing has to be added manually to the database layout!'");
return ERROR_DB_DBFIELDNOTFOUND;
$this->PrintDebugError("ER_BAD_FIELD_ERROR - Dynamically Adding field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' with Statement failed: '" . $szUpdateSql . "'");
return ERROR_DB_ADDDBFIELDFAILED;
}
}
else
{
// Return failure!
$this->PrintDebugError("ER_BAD_FIELD_ERROR - Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' is missing has to be added manually to the database layout!'");
return ERROR_DB_ADDDBFIELDFAILED;
}
}
// Reached this point means success!
return SUCCESS;
}
else
$this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc);
return ERROR_DB_DBFIELDNOTFOUND;
// Reached this point means success!
return SUCCESS;
}
/*
@ -1786,53 +1948,30 @@ class LogStreamDB extends LogStream {
/*
* Helper function to chang ethe checksum field type to unsigned INT!
* Helper function to return a list of Fields from the logstream table
*/
private function ChangeChecksumFieldUnsigned()
private function GetFieldsAsArray()
{
global $dbmapping, $fields, $querycount;
global $querycount;
// Change Checksumfield to use UNSIGNED!
$szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` CHANGE `" .
$dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "` `" .
$dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "` INT(11) UNSIGNED NOT NULL DEFAULT '0'";
// Update Table schema now!
$myQuery = mysql_query($szUpdateSql, $this->_dbhandle);
if (!$myQuery)
{
// Return failure!
$this->PrintDebugError("ER_BAD_FIELD_ERROR - Failed to Change field '" . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "' from signed to unsigned with sql statement: '" . $szUpdateSql . "'");
return ERROR_DB_CHECKSUMCHANGEFAILED;
}
// return results
return SUCCESS;
}
/*
* Helper function to chang ethe checksum field type to unsigned INT!
*/
private function CheckChecksumField()
{
global $dbmapping, $fields, $querycount;
// Verify database connection (This also opens the database!)
$res = $this->Verify();
if ( $res != SUCCESS )
return $res;
// Init Array
$arrFields = array();
$arrFieldKeys = array();
// Create SQL and Get INDEXES for table!
$szSql = "SHOW COLUMNS FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE Field = " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM];
$szSql = "SHOW FIELDS FROM " . $this->_logStreamConfigObj->DBTableName;
$myQuery = mysql_query($szSql, $this->_dbhandle);
if ($myQuery)
{
// Get result!
$myRow = mysql_fetch_array($myQuery, MYSQL_ASSOC))
if (strpos($myRow, "unsigned") !== false )
// Loop through results
while ($myRow = mysql_fetch_array($myQuery, MYSQL_ASSOC))
{
// return error code!
return ERROR_DB_CHECKSUMERROR;
// Add to index keys
$arrFieldKeys[] = strtolower($myRow['Field']);
}
// Free query now
@ -1842,8 +1981,8 @@ class LogStreamDB extends LogStream {
$querycount++;
}
// return results
return SUCCESS;
// return Array
return $arrFieldKeys;
}

View File

@ -690,12 +690,22 @@ abstract class Report {
$res = $this->_streamObj->Verify();
if ( $res == SUCCESS )
{
// Will check if certain INDEXES do exists for database logstream classes!
// Will check if all necessary fields are available!
$res = $this->_streamObj->VerifyFields( $this->_arrProperties );
if ($res != SUCCESS )
return $res;
// Will check if certain INDEXES do exists for database logstream!
$res = $this->_streamObj->VerifyIndexes( $arrProperties );
if ($res != SUCCESS )
return $res;
// Will check if certain INDEXES do exists for database logstream classes!
// Will check if checksum field is correctly configured for database logstream!
$res = $this->_streamObj->VerifyChecksumField( );
if ($res != SUCCESS )
return $res;
// Will check if TRIGGERS are installed! Requires SUPER access in database logstream!
$res = $this->_streamObj->VerifyChecksumTrigger( $myTriggerProperty );
if ($res != SUCCESS )
return $res;
@ -707,7 +717,51 @@ abstract class Report {
/**
* If the reports needs INDEXES, these are created by this function
* If the reports needs extra FIELDS, they are created by this function
*/
public function CreateMissingLogStreamFields( $mySourceID )
{
global $content, $fields;
$res = SUCCESS;
if ( $this->_streamCfgObj == null )
{
if ( isset($content['Sources'][$mySourceID]) )
{
// Obtain and get the Config Object
$this->_streamCfgObj = $content['Sources'][$mySourceID]['ObjRef'];
// Return success if logstream is FILE based!
if ( $content['Sources'][$mySourceID]['SourceType'] == SOURCE_DISK )
return SUCCESS;
}
else
return ERROR_SOURCENOTFOUND;
}
if ( $this->_streamObj == null )
{
// Create LogStream Object
$this->_streamObj = $this->_streamCfgObj->LogStreamFactory($this->_streamCfgObj);
}
// Check datasource and return result
$res = $this->_streamObj->Verify();
if ( $res == SUCCESS )
{
// Will add missing fields for this database logstream !
$res = $this->_streamObj->CreateMissingFields( $this->_arrProperties );
if ($res != SUCCESS )
return $res;
}
// return results!
return $res;
}
/**
* If the reports needs INDEXES, they are created by this function
*/
public function CreateLogStreamIndexesByPropertyArray( $mySourceID, $arrProperties )
{
@ -794,5 +848,49 @@ abstract class Report {
}
/**
* If the reports needs INDEXES, these are created by this function
*/
public function ChangeChecksumFieldUnsigned( $mySourceID )
{
global $content, $fields;
$res = SUCCESS;
if ( $this->_streamCfgObj == null )
{
if ( isset($content['Sources'][$mySourceID]) )
{
// Obtain and get the Config Object
$this->_streamCfgObj = $content['Sources'][$mySourceID]['ObjRef'];
// Return success if logstream is FILE based!
if ( $content['Sources'][$mySourceID]['SourceType'] == SOURCE_DISK )
return SUCCESS;
}
else
return ERROR_SOURCENOTFOUND;
}
if ( $this->_streamObj == null )
{
// Create LogStream Object
$this->_streamObj = $this->_streamCfgObj->LogStreamFactory($this->_streamCfgObj);
}
// Check datasource and return result
$res = $this->_streamObj->Verify();
if ( $res == SUCCESS )
{
// Will change the Checksum Field to UNSIGNED INT
$res = $this->_streamObj->ChangeChecksumFieldUnsigned( );
if ($res != SUCCESS )
return $res;
}
// return results!
return $res;
}
}
?>

View File

@ -73,6 +73,6 @@ define('ERROR_DB_INDEXFAILED', 28);
define('ERROR_DB_TRIGGERFAILED', 29);
define('ERROR_DB_CHECKSUMERROR', 30);
define('ERROR_DB_CHECKSUMCHANGEFAILED', 31);
define('ERROR_DB_ADDDBFIELDFAILED', 32);
?>

View File

@ -459,17 +459,23 @@ $content['LN_REPORTS_SAMPLELINK'] = "Report Sample";
$content['LN_REPORTS_DETAILSFOR'] = "Details for '%1' report";
$content['LN_REPORTS_PERFORMANCE_WARNING'] = "Logstream Performance Warning";
$content['LN_REPORTS_OPTIMIZE_LOGSTREAMSOURCE'] = "Yes, optimize logstream source!";
$content['LN_REPORTS_OPTIMIZE_INDEXES'] = "The datasource '%1' is not optimized for this report. There is at least one INDEX missing. Creating INDEXES will speedup the report generation. <br><br>Do you want LogAnalyter to create the necessary INDEXES now? This may take more then a few minutes, so please be patient!";
$content['LN_REPORTS_OPTIMIZE_INDEXES'] = "The datasource '%1' is not optimized for this report. There is at least one INDEX missing. Creating INDEXES will speedup the report generation. <br><br>Do you want LogAnalyzer to create the necessary INDEXES now? This may take more then a few minutes, so please be patient!";
$content['LN_REPORTS_ERROR_FAILED_CREATE_INDEXES'] = "Failed to create INDEXES for datasource '%1' with error code '%2'";
$content['LN_REPORTS_INDEX_CREATED'] = "Logstream INDEXES created";
$content['LN_REPORTS_INDEX_CREATED_SUCCESS'] = "Successfully created all INDEXES for datasource '%1'.";
$content['LN_REPORTS_OPTIMIZE_TRIGGER'] = "The datasource '%1' does not have a TRIGGER installed to automatically generate the message checksum on INSERT. Creating the TRIGGER will speedup the report generation. <br><br>Do you want LogAnalyter to create the TRIGGER now? ";
$content['LN_REPORTS_OPTIMIZE_TRIGGER'] = "The datasource '%1' does not have a TRIGGER installed to automatically generate the message checksum on INSERT. Creating the TRIGGER will speedup the report generation. <br><br>Do you want LogAnalyzer to create the TRIGGER now? ";
$content['LN_REPORTS_TRIGGER_CREATED'] = "Logstream TRIGGER created";
$content['LN_REPORTS_TRIGGER_CREATED_SUCCESS'] = "Successfully created TRIGGER for datasource '%1'.";
$content['LN_REPORTS_ERROR_FAILED_CREATE_TRIGGER'] = "Failed to create TRIGGER for datasource '%1' with error code '%2'";
$content['LN_REPORTS_CHANGE_CHECKSUM'] = "The Checksum field for datasource '%1' is not set to UNSIGNED INT. To get the report work properly, changing the CHECKSUM field to UNSIGNED INT is necessary! <br><br>Do you want LogAnalyzer to change the CHECKSUM field now? This may take more then a few minutes, so please be patient!";
$content['LN_REPORTS_ERROR_FAILED_CHANGE_CHECKSUM'] = "Failed to change the CHECKSUM field for datasource '%1' with error code '%2'";
$content['LN_REPORTS_CHECKSUM_CHANGED'] = "Checksum field changed";
$content['LN_REPORTS_CHECKSUM_CHANGED_SUCCESS'] = "Successfully changed the Checksum field for datasource '%1'.";
$content['LN_REPORTS_LOGSTREAM_WARNING'] = "Logstream Warning";
$content['LN_REPORTS_ADD_MISSINGFIELDS'] = "The datasource '%1' does not contain all necessary datafields There is at least one FIELD missing. <br><br>Do you want LogAnalyzer to create the missing datafields now?";
$content['LN_REPORTS_ERROR_FAILED_ADDING_FIELDS'] = "Failed adding missing datafields in datasource '%1' with error code '%2'";
$content['LN_REPORTS_FIELDS_CREATED'] = "Added missing datafields";
$content['LN_REPORTS_FIELDS_CREATED_SUCCESS'] = "Successfully added missing datafields for datasource '%1'.";
$content['LN_REPORTS_'] = "";
$content['LN_REPORTS_'] = "";
?>

View File

@ -5,7 +5,7 @@
<center>
<div class="table_with_border_second ErrorMsg" style="width:600px">
<div class="PriorityError">{LN_GEN_ERRORDETAILS}</div>
<p>{ERROR_MSG}</p>
<p align="left">{ERROR_MSG}</p>
</div>
<br><br>
<a href="javascript:history.back();" target="_top">{LN_GEN_ERRORRETURNPREV}</a>