From b2a37779ae9f21a4b735e9c6e53b7a62bb1381dc Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 30 Sep 2011 11:33:35 +0200 Subject: [PATCH 01/23] Added support for additional debug output if a critical error occurs (For example during a database operation) --- src/include/functions_common.php | 18 ++++++++++++++++-- src/include/functions_db.php | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/include/functions_common.php b/src/include/functions_common.php index c4fd7e4..6217651 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -1034,7 +1034,8 @@ function DieWithErrorMsg( $szerrmsg ) } else if ( $RUNMODE == RUNMODE_WEBSERVER ) { - print( + // Print main error! + print ( "Adiscon LogAnalyzer :: Critical Error occured" . "

" . "". @@ -1044,7 +1045,20 @@ function DieWithErrorMsg( $szerrmsg ) "" . "
Errordetails:
" . $szerrmsg . - "

" . + "

"); + + // Print Detail error's if available + if ( isset($content['detailederror']) ) + { + print ("". + "" . + "
Additional Errordetails:
" . + $content['detailederror'] . + "

"); + } + + // End HTML Body + print( "" ); } diff --git a/src/include/functions_db.php b/src/include/functions_db.php index 69406cb..9d63488 100644 --- a/src/include/functions_db.php +++ b/src/include/functions_db.php @@ -211,13 +211,14 @@ function DB_ReturnSimpleErrorMsg() function DB_PrintError($MyErrorMsg, $DieOrNot) { - global $n,$HTTP_COOKIE_VARS, $errdesc, $errno, $linesep; + global $content, $n,$HTTP_COOKIE_VARS, $errdesc, $errno, $linesep; $errdesc = mysql_error(); $errno = mysql_errno(); // Define global variable so we know an error has occured! - define('PHPLOGCON_INERROR', true); + if ( !defined('PHPLOGCON_INERROR') ) + define('PHPLOGCON_INERROR', true); $errormsg="Database error: $MyErrorMsg $linesep"; $errormsg.="mysql error: $errdesc $linesep"; @@ -229,7 +230,20 @@ function DB_PrintError($MyErrorMsg, $DieOrNot) if ($DieOrNot == true) DieWithErrorMsg( "$linesep" . $errormsg ); else + { OutputDebugMessage("DB_PrintError: $errormsg", DEBUG_ERROR); + + if ( !isset($content['detailederror']) ) + { + $content['detailederror_code'] = ERROR_DB_QUERYFAILED; + $content['detailederror'] = GetErrorMessage(ERROR_DB_QUERYFAILED); + } + else + $content['detailederror'] .= "

" . GetErrorMessage(ERROR_DB_QUERYFAILED); + + // Append SQL Detail Error + $content['detailederror'] .= "

" . $errormsg; + } } function DB_RemoveParserSpecialBadChars($myString) From 475c45ed624a8cc5f82c8798375ecab9863341c5 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Tue, 4 Oct 2011 15:24:37 +0200 Subject: [PATCH 02/23] Added report module for main page which is accessable with admin access. This module can be used to easily access and run reports within Loganalyzer --- src/admin/reports.php | 221 +------------------------------ src/include/functions_common.php | 4 + src/lang/en/admin.php | 12 -- src/lang/en/main.php | 20 ++- src/templates/include_menu.html | 1 + 5 files changed, 23 insertions(+), 235 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index a102ddd..65441c0 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -39,6 +39,7 @@ $gl_root_path = './../'; include($gl_root_path . 'include/functions_common.php'); include($gl_root_path . 'include/functions_frontendhelpers.php'); include($gl_root_path . 'include/functions_filters.php'); +include($gl_root_path . 'include/functions_reports.php'); // Set PAGE to be ADMINPAGE! define('IS_ADMINPAGE', true); @@ -71,8 +72,6 @@ if ( !isset($_SESSION['SESSION_ISREADONLY']) || $_SESSION['SESSION_ISREADONLY'] // --- // --- BEGIN Custom Code -// Hardcoded settings -define('URL_ONLINEREPORTS', 'http://tools.adiscon.net/listreports.php'); $content['OPTIONAL_TITLE'] = ""; // Firts of all init List of Reports! @@ -1312,224 +1311,6 @@ function InitOutputtargetDefinitions($myReport, $outputTargetDetails) } } -function CreateCronCommand( $myReportID, $mySavedReportID = null ) -{ - global $content, $gl_root_path, $myReport; - - if ( isset($mySavedReportID) ) - { - // Get Reference to report! - $myReport = $content['REPORTS'][ $myReportID ]; - - // Get reference to savedreport - $mySavedReport = $myReport['SAVEDREPORTS'][ $mySavedReportID ]; - - // Get configured Source for savedreport - $myReportSource = null; - if ( isset($content['Sources'][ $mySavedReport['sourceid'] ]) ) - $myReportSource = $content['Sources'][ $mySavedReport['sourceid'] ]; - - $pos = strpos( strtoupper(PHP_OS), "WIN"); - if ($pos !== false) - { - // Running on Windows - $phpCmd = PHP_BINDIR . "\\php.exe"; - $phpScript = realpath($gl_root_path) . "cron\\cmdreportgen.php"; - } - else - { - // Running on LINUX - $phpCmd = PHP_BINDIR . "/php"; - $phpScript = realpath($gl_root_path) . "/cron/cmdreportgen.php"; - } - - // Enable display of report command - $content['enableCronCommand'] = true; - $szCommand = $phpCmd . " " . $phpScript . " runreport " . $myReportID . " " . $mySavedReportID; - - // --- Check for user or group sources - if ( $myReportSource['userid'] != null ) - { - $szCommand .= " " . "userid=" . $myReportSource['userid']; - } - else if ( $myReportSource['groupid'] != null ) - { - $szCommand .= " " . "groupid=" . $myReportSource['groupid']; - } - // --- - } - else - { - // Disable display of report command - $content['enableCronCommand'] = false; - $szCommand = ""; - } - - // return result - return $szCommand; -} - -function InitOnlineReports() -{ - global $content; - - $xmlArray = xml2array( URL_ONLINEREPORTS ); - if ( is_array($xmlArray) && isset($xmlArray['reports']['report']) && count($xmlArray['reports']['report']) > 0 ) - { - foreach( $xmlArray['reports']['report'] as $myOnlineReport ) - { - // Copy to OnlineReports Array - $content['ONLINEREPORTS'][] = $myOnlineReport; - } - - // Success! - return true; - } - else - // Failure - return false; -} - -// Helper function from php doc -function xml2array($url, $get_attributes = 1, $priority = 'tag') -{ - $contents = ""; - if (!function_exists('xml_parser_create')) - { - return false; - } - $parser = xml_parser_create(''); - if (!($fp = @ fopen($url, 'rb'))) - { - return false; - } - while (!feof($fp)) - { - $contents .= fread($fp, 8192); - } - fclose($fp); - xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); - xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); - xml_parse_into_struct($parser, trim($contents), $xml_values); - xml_parser_free($parser); - if (!$xml_values) - return; //Hmm... - $xml_array = array (); - $parents = array (); - $opened_tags = array (); - $arr = array (); - $current = & $xml_array; - $repeated_tag_index = array (); - foreach ($xml_values as $data) - { - unset ($attributes, $value); - extract($data); - $result = array (); - $attributes_data = array (); - if (isset ($value)) - { - if ($priority == 'tag') - $result = $value; - else - $result['value'] = $value; - } - if (isset ($attributes) and $get_attributes) - { - foreach ($attributes as $attr => $val) - { - if ($priority == 'tag') - $attributes_data[$attr] = $val; - else - $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' - } - } - if ($type == "open") - { - $parent[$level -1] = & $current; - if (!is_array($current) or (!in_array($tag, array_keys($current)))) - { - $current[$tag] = $result; - if ($attributes_data) - $current[$tag . '_attr'] = $attributes_data; - $repeated_tag_index[$tag . '_' . $level] = 1; - $current = & $current[$tag]; - } - else - { - if (isset ($current[$tag][0])) - { - $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; - $repeated_tag_index[$tag . '_' . $level]++; - } - else - { - $current[$tag] = array ( - $current[$tag], - $result - ); - $repeated_tag_index[$tag . '_' . $level] = 2; - if (isset ($current[$tag . '_attr'])) - { - $current[$tag]['0_attr'] = $current[$tag . '_attr']; - unset ($current[$tag . '_attr']); - } - } - $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; - $current = & $current[$tag][$last_item_index]; - } - } - elseif ($type == "complete") - { - if (!isset ($current[$tag])) - { - $current[$tag] = $result; - $repeated_tag_index[$tag . '_' . $level] = 1; - if ($priority == 'tag' and $attributes_data) - $current[$tag . '_attr'] = $attributes_data; - } - else - { - if (isset ($current[$tag][0]) and is_array($current[$tag])) - { - $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; - if ($priority == 'tag' and $get_attributes and $attributes_data) - { - $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; - } - $repeated_tag_index[$tag . '_' . $level]++; - } - else - { - $current[$tag] = array ( - $current[$tag], - $result - ); - $repeated_tag_index[$tag . '_' . $level] = 1; - if ($priority == 'tag' and $get_attributes) - { - if (isset ($current[$tag . '_attr'])) - { - $current[$tag]['0_attr'] = $current[$tag . '_attr']; - unset ($current[$tag . '_attr']); - } - if ($attributes_data) - { - $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; - } - } - $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken - } - } - } - elseif ($type == 'close') - { - $current = & $parent[$level -1]; - } - } - return ($xml_array); -} - /* * Helper functions to init a Datefield */ diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 6217651..d0d56d5 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -72,6 +72,9 @@ $content['TITLE'] = "Adiscon LogAnalyzer :: Release " . $content['BUILDNUMBER']; $content['BASEPATH'] = $gl_root_path; $content['SHOW_DONATEBUTTON'] = true; // Default = true! +// Hardcoded DEFINES +define('URL_ONLINEREPORTS', 'http://tools.adiscon.net/listreports.php'); + // PreInit overall user variables $content['EXTRA_PHPLOGCON_LOGO'] = $content['BASEPATH'] . "images/main/Header-Logo.png"; $content['EXTRA_METATAGS'] = ""; @@ -733,6 +736,7 @@ function InitFrontEndVariables() $content['MENU_WINDOWLIST'] = $content['BASEPATH'] . "images/icons/windows.png"; $content['MENU_CHECKED'] = $content['BASEPATH'] . "images/icons/check.png"; $content['MENU_PLAY_GREEN'] = $content['BASEPATH'] . "images/icons/bullet_triangle_green.png"; + $content['MENU_PLAY_GREEN_WINDOW'] = $content['BASEPATH'] . "images/icons/table_sql_run.png"; $content['MENU_PAGER_BEGIN'] = $content['BASEPATH'] . "images/icons/media_beginning.png"; $content['MENU_PAGER_PREVIOUS'] = $content['BASEPATH'] . "images/icons/media_rewind.png"; diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index 363b921..e0e2eb6 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -407,15 +407,8 @@ $content['LN_CMD_'] = ""; // Report Options $content['LN_REPORTS_EDIT'] = "Edit Report"; $content['LN_REPORTS_DELETE'] = "Remove Report"; -$content['LN_REPORTS_CAT'] = "Report Category"; -$content['LN_REPORTS_ID'] = "Report ID"; -$content['LN_REPORTS_NAME'] = "Report Name"; -$content['LN_REPORTS_DESCRIPTION'] = "Report Description"; $content['LN_REPORTS_REQUIREDFIELDS'] = "Required Fields"; $content['LN_REPORTS_ERROR_NOREPORTS'] = "There were no valid reports found in your installation."; -$content['LN_REPORTS_HELP'] = "Help"; -$content['LN_REPORTS_HELP_CLICK'] = "Click here for a detailed report description"; -$content['LN_REPORTS_INFO'] = "Show more Information"; $content['LN_REPORTS_INIT'] = "Initialize settings"; $content['LN_REPORTS_REMOVE'] = "Remove settings"; $content['LN_REPORTS_ERROR_IDNOTFOUND'] = "There was no report with ID '%1' found."; @@ -439,7 +432,6 @@ $content['LN_REPORTS_HASBEENEDIT'] = "The Savedreport '%1' has been successfully $content['LN_REPORTS_SOURCEID'] = "Logstream source"; $content['LN_REPORTS_ERROR_SAVEDREPORTIDNOTFOUND'] = "There was no savedreport with ID '%1' found."; $content['LN_REPORTS_ERROR_INVALIDSAVEDREPORTID'] = "Invalid savedreport id."; -$content['LN_REPORTS_SAVEDREPORTS'] = "Saved reports"; $content['LN_REPORTS_RUNNOW'] = "Run saved report now!"; $content['LN_REPORTS_WARNDELETESAVEDREPORT'] = "Are you sure that you want to delete the savedreport '%1'?"; $content['LN_REPORTS_ERROR_DELSAVEDREPORT'] = "Deleting of the savedreport with id '%1' failed!"; @@ -459,8 +451,6 @@ $content['LN_REPORTS_ADVANCEDFILTERLIST'] = "List of advanced report filters"; $content['LN_REPORTS_OUTPUTTARGET_DETAILS'] = "Outputtarget Options"; $content['LN_REPORTS_OUTPUTTARGET_FILE'] = "Output Path and Filename"; $content['LN_REPORTS_CRONCMD'] = "Local Report command"; -$content['LN_REPORTMENU_LIST'] = "List installed Reports"; -$content['LN_REPORTMENU_ONLINELIST'] = "All Available Reports"; $content['LN_REPORTS_LINKS'] = "Related Links"; $content['LN_REPORTS_INSTALLED'] = "Installed"; $content['LN_REPORTS_NOTINSTALLED'] = "Not installed"; @@ -468,7 +458,5 @@ $content['LN_REPORTS_DOWNLOAD'] = "Download Link"; $content['LN_REPORTS_SAMPLELINK'] = "Report Sample"; $content['LN_REPORTS_DETAILSFOR'] = "Details for '%1' report"; $content['LN_REPORTS_'] = ""; -$content['LN_REPORTS_'] = ""; -$content['LN_REPORTS_'] = ""; ?> \ No newline at end of file diff --git a/src/lang/en/main.php b/src/lang/en/main.php index 5cceb72..171957a 100644 --- a/src/lang/en/main.php +++ b/src/lang/en/main.php @@ -124,9 +124,9 @@ $content['LN_MENU_LOGOFF'] = "Logoff"; $content['LN_MENU_LOGGEDINAS'] = "Logged in as"; $content['LN_MENU_MAXVIEW'] = "Maximize View"; $content['LN_MENU_NORMALVIEW'] = "Normalize View"; - $content['LN_MENU_STATISTICS'] = "Statistics"; - $content['LN_MENU_CLICKTOEXPANDMENU'] = "Click the icon to show the menu"; - +$content['LN_MENU_STATISTICS'] = "Statistics"; +$content['LN_MENU_CLICKTOEXPANDMENU'] = "Click the icon to show the menu"; + $content['LN_MENU_REPORTS'] = "Reports"; // Main Index Site $content['LN_ERROR_INSTALLFILEREMINDER'] = "Warning! You still have NOT removed the 'install.php' from your LogAnalyzer main directory!"; @@ -339,6 +339,7 @@ $content['LN_ORACLE_FIELD'] = "Field"; $content['LN_ORACLE_ONLINESEARCH'] = "Online Search"; $content['LN_ORACLE_WHOIS'] = "WHOIS Lookup for '%1' value '%2'"; +// Report Strings $content['LN_GEN_ERROR_INVALIDOP'] = "Invalid or missing operation type"; $content['LN_GEN_ERROR_INVALIDREPORTID'] = "Invalid or missing report id"; $content['LN_GEN_ERROR_MISSINGSAVEDREPORTID'] = "Invalid or missing savedreport id"; @@ -363,5 +364,18 @@ $content['LN_CMD_NOSAVEDREPORTID'] = "Missing SavedReport ID"; $content['LN_CMD_NOCMDPROMPT'] = "Error, this script can only be run from the command prompt."; $content['LN_REPORT_GENERATEDTIME'] = "Report generated at: "; +$content['LN_REPORT_ACTIONS'] = "Run Report Actions"; +$content['LN_REPORTS_CAT'] = "Report Category"; +$content['LN_REPORTS_ID'] = "Report ID"; +$content['LN_REPORTS_NAME'] = "Report Name"; +$content['LN_REPORTS_DESCRIPTION'] = "Report Description"; +$content['LN_REPORTS_HELP'] = "Help"; +$content['LN_REPORTS_HELP_CLICK'] = "Click here for a detailed report description"; +$content['LN_REPORTS_INFO'] = "Show more Information"; +$content['LN_REPORTS_SAVEDREPORTS'] = "Saved reports"; +$content['LN_REPORTS_ADMIN'] = "Administrate Reports"; +$content['LN_REPORTMENU_LIST'] = "List installed Reports"; +$content['LN_REPORTMENU_ONLINELIST'] = "All Available Reports"; + ?> \ No newline at end of file diff --git a/src/templates/include_menu.html b/src/templates/include_menu.html index 066eba2..1526de1 100644 --- a/src/templates/include_menu.html +++ b/src/templates/include_menu.html @@ -4,6 +4,7 @@ {LN_MENU_SEARCH} {LN_MENU_SHOWEVENTS} {LN_MENU_STATISTICS} + {LN_MENU_REPORTS} - {LN_MENU_SEARCHINKB} + {LN_MENU_SEARCHINKB} {LN_MENU_LOGIN} diff --git a/src/templates/reports.html b/src/templates/reports.html new file mode 100644 index 0000000..122fb09 --- /dev/null +++ b/src/templates/reports.html @@ -0,0 +1,221 @@ + + + +

+
+
+
{LN_GEN_ERRORDETAILS}
+

{ERROR_MSG}

+

+ + + {LN_GEN_MOREINFORMATION} + +

+
+

+
+

+ + + + + + + + + + + + + +
{LN_MENU_REPORTS}

{LN_REPORTS_INFORMATION}

+ + + + + + + + + + + +
{LN_REPORTS_ADMIN}{LN_REPORTMENU_ONLINELIST}{REPORTS_DETAILSFOR} 
+ +
+ +

+ + + +{rowbegin} +
+ + + + + + + + + + + + + + + + +
{LN_REPORTS_NAME}{DisplayName}
{LN_REPORTS_HELP} + +    {LN_REPORTS_HELP} + +    {LN_REPORTS_INFO} +
{LN_REPORTS_DESCRIPTION}{Description}
{LN_REPORTS_SAVEDREPORTS} + + + + + + + + + +
+ + {customTitle} + +   +
+ + +
+

+{rowend} + + + + + + + + + + + + + + + + + + + + + + +
{LN_REPORTS_INSTALLED}{LN_REPORTS_ID}{LN_REPORTS_NAME}{LN_REPORTS_DESCRIPTION}{LN_REPORTS_LINKS}
{reportid} + + {reportname} + + + {reportname} + + {reportdescription} + +    + + +    + + +    + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{LN_REPORTS_DETAILS}
{LN_REPORTS_CAT}{Category}
{LN_REPORTS_ID}{ReportID}
{LN_REPORTS_NAME}{DisplayName}
{LN_REPORTS_DESCRIPTION}{Description}
{LN_REPORTS_REQUIREDFIELDS} + +
{FieldCaption} ({FieldDefine}) + +

+
{LN_REPORTS_HELP}{LN_REPORTS_HELP_CLICK}
+ + {LN_REPORTS_INIT} + + + {LN_REPORTS_REMOVE} + +
{LN_REPORTS_SAVEDREPORTS} +
+ + {customTitle} + +   +   +   +
+ +

+ {LN_GEN_ERRORRETURNPREV} + + +

+ + + + + + \ No newline at end of file From d53b76dce6d025482a8306da76a3f6460fbea1de Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Tue, 25 Oct 2011 13:39:30 +0200 Subject: [PATCH 04/23] Fixed bug in syslog summary report missing checksum in report generation --- src/classes/reports/report.syslog.syslogsummary.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index 95b8e2c..65386d7 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -336,8 +336,11 @@ class Report_syslogsummary extends Report { $logArray[MISC_CHECKSUM] = crc32( $logArray[SYSLOG_MESSAGE] ); // Maybe useful somewhere else: sprintf( "%u", crc32 ( $logArray[SYSLOG_MESSAGE] )); $strChecksum = $logArray[MISC_CHECKSUM]; - // TODO, save calculated Checksum into DB! + // Save calculated Checksum into DB! + $this->_streamObj->SaveMessageChecksum($logArray); } + else // Get checksum + $strChecksum = $logArray[MISC_CHECKSUM]; // Check if entry exists in result array if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]) ) From 9b95b35c811d6fd23c45f6cdc10a25053cd9058d Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 26 Oct 2011 15:54:59 +0200 Subject: [PATCH 05/23] Syslog report: Moved Event Count Row to left Enhanced Syslog report generation performance. Needed some changes in the basic report class. --- src/classes/logstream.class.php | 29 +- src/classes/logstreamdb.class.php | 40 ++- .../report.syslog.syslogsummary.class.php | 269 ++++++++++-------- .../report.syslog.syslogsummary.template.html | 15 +- .../report.syslog.syslogsummary.template.pdf | 12 +- src/include/functions_common.php | 6 +- 6 files changed, 230 insertions(+), 141 deletions(-) diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index ed5f65d..728562c 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -207,7 +207,7 @@ abstract class LogStream { * * @return integer Error stat */ - public abstract function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $bIncludeLogStreamFields = false); + public abstract function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $bIncludeLogStreamFields = false, $bIncludeMinMaxDateFields = false); /** @@ -252,6 +252,11 @@ abstract class LogStream { public abstract function SaveMessageChecksum( $arrProperitesIn ); + /* + * Helper function for logstream classes to clear filter based stuff + */ + public abstract function ResetFilters( ); + /* * Helper functino to trigger initialisation of MsgParsers */ @@ -276,6 +281,9 @@ abstract class LogStream { OutputDebugMessage("SetFilter combined = '" . $finalfilters . "'. ", DEBUG_DEBUG); + // Reset Filters first to make sure we do not add multiple filters! + $this->_filters = null; + // Parse Filters from string $this->ParseFilters($finalfilters); @@ -585,6 +593,23 @@ abstract class LogStream { return null; } + /* + * Helper function to get the internal Field ID by database field name! + */ + public function GetFieldIDbyDatabaseMapping($szTableType, $szFieldName) + { + global $content, $dbmapping; + + foreach( $dbmapping[$szTableType]['DBMAPPINGS'] as $myFieldID => $myDBMapping ) + { + if ( $myDBMapping == $szFieldName ) + return $myFieldID; + } + + // Default return! + return $szFieldName; + } + /* * --- PIRVATE HELPERS! */ @@ -1182,7 +1207,5 @@ abstract class LogStream { return -1; } - - } ?> \ No newline at end of file diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 10e9ca2..598ccca 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -112,6 +112,15 @@ class LogStreamDB extends LogStream { return SUCCESS; } + /* + * Helper function to clear the current querystring! + */ + public function ResetFilters() + { + // Clear _SQLwhereClause variable! + $this->_SQLwhereClause = ""; + } + /** * Close the database connection. * @@ -744,7 +753,7 @@ class LogStreamDB extends LogStream { * * @return integer Error stat */ - public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $aIncludeCustomFields = null, $bIncludeLogStreamFields = false) + public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $aIncludeCustomFields = null, $bIncludeLogStreamFields = false, $bIncludeMinMaxDateFields = false) { global $content, $dbmapping, $fields; @@ -793,13 +802,20 @@ class LogStreamDB extends LogStream { } else // Only Include ConsolidateField $myDBQueryFields = $myDBConsFieldName . ", "; - + + // Add Min and Max fields for DATE if desired + if ( $bIncludeMinMaxDateFields ) + { + $myDBQueryFields .= "Min(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as FirstOccurrence_Date, "; + $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as LastOccurrence_Date, "; + } + if ( $szConsFieldId == $szSortFieldId ) $myDBSortedFieldName = "ItemCount"; else $myDBSortedFieldName = $szSortFieldId; // --- - + // Special handling for date fields if ( $nConsFieldType == FILTER_TYPE_DATE ) { @@ -815,7 +831,7 @@ class LogStreamDB extends LogStream { $szLimitSql = ""; // Create SQL Where Clause! - if ( $this->_SQLwhereClause == "" ) + if ( strlen($this->_SQLwhereClause) <= 0 ) { $res = $this->CreateSQLWhereClause(); if ( $res != SUCCESS ) @@ -832,11 +848,14 @@ class LogStreamDB extends LogStream { " ORDER BY " . $myDBSortedFieldName . " " . $szSortingOrder . $szLimitSql ; + // Output Debug Informations + OutputDebugMessage("LogStreamDB|ConsolidateDataByField: Running Created SQL Query:
" . $szSql, DEBUG_DEBUG); + // Perform Database Query $myquery = mysql_query($szSql, $this->_dbhandle); if ( !$myquery ) return ERROR_DB_QUERYFAILED; - + // Initialize Array variable $aResult = array(); @@ -848,12 +867,17 @@ class LogStreamDB extends LogStream { foreach ( $myRow as $myFieldName => $myFieldValue ) { - if ( $myFieldName == $dbmapping[$szTableType]['DBMAPPINGS'][$szConsFieldId] ) + $myFieldID = $this->GetFieldIDbyDatabaseMapping($szTableType, $myFieldName); + $aNewRow[ $myFieldID ] = $myFieldValue; + +/* if ( $myFieldName == $dbmapping[$szTableType]['DBMAPPINGS'][$szConsFieldId] ) $aNewRow[$szConsFieldId] = $myFieldValue; else + { $aNewRow[$myFieldName] = $myFieldValue; +*/ +// } } - // Add new row to result $aResult[] = $aNewRow; } @@ -865,7 +889,6 @@ class LogStreamDB extends LogStream { return ERROR_NOMORERECORDS; } - /** * Implementation of GetCountSortedByField * @@ -939,6 +962,7 @@ class LogStreamDB extends LogStream { } + /* * ============= Beginn of private functions ============= */ diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index 65386d7..6dd1177 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -293,148 +293,191 @@ class Report_syslogsummary extends Report { */ private function ConsolidateSyslogmessagesPerHost( $arrHosts ) { - global $content, $gl_starttime; + global $content, $gl_starttime, $fields; // Now open the stream for data processing $res = $this->_streamObj->Open( $this->_arrProperties, true ); if ( $res == SUCCESS ) { - // Set reading direction -// $this->_streamObj->SetReadDirection( EnumReadDirection::Backward ); - - // Init uid helper - $uID = UID_UNKNOWN; - - // Set position to BEGIN of FILE - $this->_streamObj->Sseek($uID, EnumSeek::BOS, 0); - - // Start reading data - $ret = $this->_streamObj->Read($uID, $logArray); - + if ( true ) + { + // --- New Method to consolidate data! // TimeStats $nowtime = microtime_float(); $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; - // Found first data record - if ( $ret == SUCCESS ) + foreach ( $arrHosts as $myHost ) { - do + // Set custom filters + $this->_streamObj->ResetFilters(); + $this->_streamObj->SetFilter( $this->_filterString . " " . $fields[SYSLOG_MESSAGETYPE]['SearchField'] . ":=" . IUT_Syslog . " " . $fields[SYSLOG_HOST]['SearchField'] . ":=" . $myHost ); + + // Set Host Item Basics if not set yet + $content["report_consdata"][ $myHost ][SYSLOG_HOST] = $myHost; + + // Get Data for single host + $content["report_consdata"][ $myHost ]['cons_msgs'] = $this->_streamObj->ConsolidateDataByField( MISC_CHECKSUM, $this->_maxMsgsPerHost, MISC_CHECKSUM, SORTING_ORDER_DESC, null, true, true ); + + //print_r ($fields[SYSLOG_MESSAGE]); + foreach ( $content["report_consdata"][ $myHost ]['cons_msgs'] as &$myConsData ) { - // Check if Event from host is in our hosts array - if ( in_array($logArray[SYSLOG_HOST], $arrHosts) ) + // Set Basic data entries + if (!isset( $content['filter_facility_list'][$myConsData[SYSLOG_FACILITY]] )) + $myConsData[SYSLOG_FACILITY] = SYSLOG_LOCAL0; // Set default in this case + if (!isset( $content['filter_severity_list'][$myConsData[SYSLOG_SEVERITY]] )) + $myConsData[SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case + + // Set Counter and First/Last Event date + $myConsData['FirstOccurrence_Date'] = $myConsData[SYSLOG_DATE]; + $myConsData['LastOccurrence_Date'] = $myConsData[SYSLOG_DATE]; + } + + } + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + // --- + } + else + { + // --- Old Method! + // Init uid helper + $uID = UID_UNKNOWN; + + // Set position to BEGIN of FILE + $this->_streamObj->Sseek($uID, EnumSeek::BOS, 0); + + // Start reading data + $ret = $this->_streamObj->Read($uID, $logArray); + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + + // Found first data record + if ( $ret == SUCCESS ) + { + do { - // Set Host Item Basics if not set yet - if ( !isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST]) ) + // Check if Event from host is in our hosts array + if ( in_array($logArray[SYSLOG_HOST], $arrHosts) ) { - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST] = $logArray[SYSLOG_HOST]; - } + // Set Host Item Basics if not set yet + if ( !isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST]) ) + { + $content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST] = $logArray[SYSLOG_HOST]; + } - // Calc checksum - if ( !isset($logArray[MISC_CHECKSUM]) || $logArray[MISC_CHECKSUM] == 0 ) - { - // Calc crc32 from message, we use this as index - $logArray[MISC_CHECKSUM] = crc32( $logArray[SYSLOG_MESSAGE] ); // Maybe useful somewhere else: sprintf( "%u", crc32 ( $logArray[SYSLOG_MESSAGE] )); - $strChecksum = $logArray[MISC_CHECKSUM]; + // Calc checksum + if ( !isset($logArray[MISC_CHECKSUM]) || $logArray[MISC_CHECKSUM] == 0 ) + { + // Calc crc32 from message, we use this as index + $logArray[MISC_CHECKSUM] = crc32( $logArray[SYSLOG_MESSAGE] ); // Maybe useful somewhere else: sprintf( "%u", crc32 ( $logArray[SYSLOG_MESSAGE] )); + $strChecksum = $logArray[MISC_CHECKSUM]; - // Save calculated Checksum into DB! - $this->_streamObj->SaveMessageChecksum($logArray); - } - else // Get checksum - $strChecksum = $logArray[MISC_CHECKSUM]; + // Save calculated Checksum into DB! + $this->_streamObj->SaveMessageChecksum($logArray); + } + else // Get checksum + $strChecksum = $logArray[MISC_CHECKSUM]; - // Check if entry exists in result array - if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]) ) - { - // Increment counter and set First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount']++; - - // Set FirstEvent date if necessary! - if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'][EVTIME_TIMESTAMP] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; + // Check if entry exists in result array + if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]) ) + { + // Increment counter and set First/Last Event date + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount']++; + + // Set FirstEvent date if necessary! + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'][EVTIME_TIMESTAMP] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; - // Set LastEvent date if necessary! - if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'][EVTIME_TIMESTAMP] ) + // Set LastEvent date if necessary! + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'][EVTIME_TIMESTAMP] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + } + else + { + // Set Basic data entries + if (isset( $content['filter_facility_list'][$logArray[SYSLOG_FACILITY]] )) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = $logArray[SYSLOG_FACILITY]; + else + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = SYSLOG_LOCAL0; // Set default in this case + if (isset( $content['filter_severity_list'][$logArray[SYSLOG_SEVERITY]] )) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY]; + else + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SYSLOGTAG] = $logArray[SYSLOG_SYSLOGTAG]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE]; + + // Set Counter and First/Last Event date + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount'] = 1; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + } } - else - { - // Set Basic data entries - if (isset( $content['filter_facility_list'][$logArray[SYSLOG_FACILITY]] )) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = $logArray[SYSLOG_FACILITY]; - else - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = SYSLOG_LOCAL0; // Set default in this case - if (isset( $content['filter_severity_list'][$logArray[SYSLOG_SEVERITY]] )) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY]; - else - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SYSLOGTAG] = $logArray[SYSLOG_SYSLOGTAG]; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE]; - // Set Counter and First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount'] = 1; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; - } + // Get next data record + $ret = $this->_streamObj->ReadNext($uID, $logArray); + } while ( $ret == SUCCESS ); + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + } + else + return $ret; + } + + + // --- Start Postprocessing + foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) + { + // First use callback function to sort array + uasort($tmpConsolidatedComputer['cons_msgs'], "MultiSortArrayByItemCountDesc"); + + // Remove entries according to _maxMsgsPerHost + if ( count($tmpConsolidatedComputer['cons_msgs']) > $this->_maxMsgsPerHost ) + { + $iDropCount = 0; + + do + { + array_pop($tmpConsolidatedComputer['cons_msgs']); + $iDropCount++; + } while ( count($tmpConsolidatedComputer['cons_msgs']) > $this->_maxMsgsPerHost ); + + // Append a dummy entry which shows count of all other events + if ( $iDropCount > 0 ) + { + $lastEntry[SYSLOG_SEVERITY] = SYSLOG_NOTICE; + $lastEntry[SYSLOG_FACILITY] = SYSLOG_LOCAL0; + $lastEntry[SYSLOG_SYSLOGTAG] = $content['LN_GEN_ALL_OTHER_EVENTS']; + $lastEntry[SYSLOG_MESSAGE] = $content['LN_GEN_ALL_OTHER_EVENTS']; + $lastEntry['ItemCount'] = $iDropCount; + $lastEntry['FirstOccurrence_Date'] = "-"; + $lastEntry['LastOccurrence_Date'] = "-"; + + $tmpConsolidatedComputer['cons_msgs'][] = $lastEntry; } - - // Get next data record - $ret = $this->_streamObj->ReadNext($uID, $logArray); - } while ( $ret == SUCCESS ); + } // TimeStats $nowtime = microtime_float(); $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; - // Start Postprocessing - foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) + // PostProcess Events! + foreach( $tmpConsolidatedComputer["cons_msgs"] as &$tmpMyEvent ) { - // First use callback function to sort array - uasort($tmpConsolidatedComputer['cons_msgs'], "MultiSortArrayByItemCountDesc"); - - // Remove entries according to _maxMsgsPerHost - if ( count($tmpConsolidatedComputer['cons_msgs']) > $this->_maxMsgsPerHost ) - { - $iDropCount = 0; - - do - { - array_pop($tmpConsolidatedComputer['cons_msgs']); - $iDropCount++; - } while ( count($tmpConsolidatedComputer['cons_msgs']) > $this->_maxMsgsPerHost ); - - // Append a dummy entry which shows count of all other events - if ( $iDropCount > 0 ) - { - $lastEntry[SYSLOG_SEVERITY] = SYSLOG_NOTICE; - $lastEntry[SYSLOG_FACILITY] = SYSLOG_LOCAL0; - $lastEntry[SYSLOG_SYSLOGTAG] = $content['LN_GEN_ALL_OTHER_EVENTS']; - $lastEntry[SYSLOG_MESSAGE] = $content['LN_GEN_ALL_OTHER_EVENTS']; - $lastEntry['ItemCount'] = $iDropCount; - $lastEntry['FirstOccurrence_Date'] = "-"; - $lastEntry['LastOccurrence_Date'] = "-"; - - $tmpConsolidatedComputer['cons_msgs'][] = $lastEntry; - } - } - - // TimeStats - $nowtime = microtime_float(); - $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; - - // PostProcess Events! - foreach( $tmpConsolidatedComputer["cons_msgs"] as &$tmpMyEvent ) - { - $tmpMyEvent['FirstOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['FirstOccurrence_Date'] ); - $tmpMyEvent['LastOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['LastOccurrence_Date'] ); - $tmpMyEvent['syslogseverity_text'] = $this->GetSeverityDisplayName($tmpMyEvent['syslogseverity']); //$content['filter_severity_list'][ $tmpMyEvent['syslogseverity'] ]["DisplayName"]; - $tmpMyEvent['syslogfacility_text'] = $this->GetFacilityDisplayName($tmpMyEvent['syslogfacility']); //$content['filter_facility_list'][ $tmpMyEvent['syslogfacility'] ]["DisplayName"]; - $tmpMyEvent['syslogseverity_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogseverity']); - $tmpMyEvent['syslogfacility_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogfacility']); - } + $tmpMyEvent['FirstOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['FirstOccurrence_Date'] ); + $tmpMyEvent['LastOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['LastOccurrence_Date'] ); + $tmpMyEvent['syslogseverity_text'] = $this->GetSeverityDisplayName($tmpMyEvent['syslogseverity']); //$content['filter_severity_list'][ $tmpMyEvent['syslogseverity'] ]["DisplayName"]; + $tmpMyEvent['syslogfacility_text'] = $this->GetFacilityDisplayName($tmpMyEvent['syslogfacility']); //$content['filter_facility_list'][ $tmpMyEvent['syslogfacility'] ]["DisplayName"]; + $tmpMyEvent['syslogseverity_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogseverity']); + $tmpMyEvent['syslogfacility_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogfacility']); } } - else - return $ret; + // --- } // Work done! diff --git a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html index 766b4e2..1587356 100644 --- a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html +++ b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html @@ -95,30 +95,29 @@ + - - - - - - - - + + + + + + diff --git a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf index 6daa3c9..021a379 100644 --- a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf +++ b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf @@ -68,27 +68,27 @@
{ln_report_number}{ln_report_count} {ln_report_firstoccurrence} {ln_report_lastoccurrence} {ln_report_severity} {ln_report_facility} {ln_report_syslogtag} {ln_report_description}{ln_report_count}
{ZAEHLER}{FirstOccurrence_Date_Formatted}{LastOccurrence_Date_Formatted}{syslogseverity_text}{syslogfacility_text}{syslogtag}{msg} {ItemCount} {ItemCount} {FirstOccurrence_Date_Formatted}{LastOccurrence_Date_Formatted}{syslogseverity_text}{syslogfacility_text}{syslogtag}{msg}
+ - - - - - - + + + + + diff --git a/src/include/functions_common.php b/src/include/functions_common.php index d0d56d5..fa90ce3 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -566,8 +566,8 @@ function CheckAndSetRunMode() // Define and Inits Syslog variables now! // DEPRECIATED! define_syslog_variables(); // Syslog Constants are defined by default anyway! - openlog("LogAnalyzer", LOG_PID, LOG_USER); - + $syslogOpened = openlog("LogAnalyzer", LOG_PID, LOG_USER); + // --- Check necessary PHP Extensions! $loadedExtensions = get_loaded_extensions(); @@ -1347,7 +1347,7 @@ function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) // Check if the user wants to syslog the error! if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 ) { - syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); + $syslogSend = syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); } } From b488be53a1bfe17e9f068bba858193b8b287cd70 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 26 Oct 2011 16:13:02 +0200 Subject: [PATCH 06/23] Fixed filter edit handling in report admin, which was broken because of changes in last version --- src/admin/reports.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index 65441c0..54e7427 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -589,9 +589,9 @@ if ( isset($content['ISADDSAVEDREPORT']) && $content['ISADDSAVEDREPORT'] ) $szFilterString = ""; if ( - ( strlen($content['filterString']) <= 0 && - isset($_POST['report_filterString']) ) - || +// ( strlen($content['filterString']) <= 0 && +// isset($_POST['report_filterString']) ) +// || ( strlen($content['filterString']) > 0 && !isset($_POST['subop']) && !isset($_POST['subop_edit']) && @@ -739,10 +739,20 @@ if ( isset($content['ISADDSAVEDREPORT']) && $content['ISADDSAVEDREPORT'] ) $i++; } -// DEBUG stuff -// echo $content['filterString'] . "
\r\n"; -// echo $szFilterString . "
\r\n"; -// print_r ( $AllFilters ); + // Reset Allfilters Array to NULL in this case! + if ( strlen($szFilterString) <= 0 ) + { + $content['filterString'] = ""; + $content['filterString_htmlform'] = ""; + } + + /* + // DEBUG stuff + echo $content['filterString'] . "
\r\n"; + echo $szFilterString . "
\r\n"; + print_r ( $AllFilters ); + // */ + } } @@ -796,7 +806,10 @@ if ( isset($content['ISADDSAVEDREPORT']) && $content['ISADDSAVEDREPORT'] ) } // Copy Final Filterstring if necessary if ( strlen($szFilterString) > 0 ) + { $content['filterString'] = $szFilterString; + $content['filterString_htmlform'] = htmlspecialchars($szFilterString); + } // echo $content['SourceID']; if ( isset($content['Sources'][$content['SourceID']]['ObjRef']) ) From d16513682794b734e462e5c522d41be97b70bdea Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 26 Oct 2011 17:24:06 +0200 Subject: [PATCH 07/23] Added changes to other logstream classed needed due the changes in syslog report --- src/classes/logstreamdisk.class.php | 16 +++++++++++- src/classes/logstreampdo.class.php | 25 ++++++++++++++++++- .../report.syslog.syslogsummary.class.php | 5 ---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index f78f7bf..5568a50 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -92,6 +92,14 @@ class LogStreamDisk extends LogStream { return SUCCESS; } + /* + * Helper function to clear the current querystring! + */ + public function ResetFilters() + { + // nothing todo in this logstream + } + /** * Close the file. * @@ -752,7 +760,7 @@ class LogStreamDisk extends LogStream { * * @return integer Error stat */ - public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $aIncludeCustomFields = null, $bIncludeLogStreamFields = false) + public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $aIncludeCustomFields = null, $bIncludeLogStreamFields = false, $bIncludeMinMaxDateFields = false) { global $content, $fields; @@ -790,7 +798,10 @@ class LogStreamDisk extends LogStream { $myFieldData = $content['LN_STATS_OTHERS']; if ( isset($aResult[ $myFieldData ]) ) + { $aResult[ $myFieldData ]['ItemCount']++; + $aResult[ $myFieldData ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + } else { // Initialize entry if we haven't exceeded the RecordLImit yet! @@ -811,6 +822,9 @@ class LogStreamDisk extends LogStream { $aResult[ $myFieldData ][$szSortFieldId] = $logArray[$szSortFieldId]; $aResult[ $myFieldData ]['ItemCount'] = 1; + + $aResult[ $myFieldData ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; + $aResult[ $myFieldData ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; } else { diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 5929402..bc4eefb 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -118,6 +118,15 @@ class LogStreamPDO extends LogStream { return SUCCESS; } + /* + * Helper function to clear the current querystring! + */ + public function ResetFilters() + { + // Clear _SQLwhereClause variable! + $this->_SQLwhereClause = ""; + } + /** * Close the database connection. * @@ -864,7 +873,7 @@ class LogStreamPDO extends LogStream { * * @return integer Error stat */ - public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $aIncludeCustomFields = null, $bIncludeLogStreamFields = false) + public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFieldId, $nSortingOrder, $aIncludeCustomFields = null, $bIncludeLogStreamFields = false, $bIncludeMinMaxDateFields = false) { global $content, $dbmapping, $fields;; @@ -914,6 +923,13 @@ class LogStreamPDO extends LogStream { else // Only Include ConsolidateField $myDBQueryFields = $myDBConsFieldName . ", "; + // Add Min and Max fields for DATE if desired + if ( $bIncludeMinMaxDateFields ) + { + $myDBQueryFields .= "Min(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as FirstOccurrence_Date, "; + $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as LastOccurrence_Date, "; + } + if ( $szConsFieldId == $szSortFieldId ) $myDBSortedFieldName = "ItemCount"; else @@ -960,6 +976,9 @@ class LogStreamPDO extends LogStream { " ORDER BY " . $myDBSortedFieldName . " " . $szSortingOrder . $szLimitSql ; + // Output Debug Informations + OutputDebugMessage("LogStreamPDO|ConsolidateDataByField: Running Created SQL Query:
" . $szSql, DEBUG_DEBUG); + // Perform Database Query $this->_myDBQuery = $this->_dbhandle->query($szSql); if ( !$this->_myDBQuery ) @@ -984,10 +1003,14 @@ class LogStreamPDO extends LogStream { foreach ( $myRow as $myFieldName => $myFieldValue ) { + $myFieldID = $this->GetFieldIDbyDatabaseMapping($szTableType, $myFieldName); + $aNewRow[ $myFieldID ] = $myFieldValue; + /* if ( $myFieldName == $dbmapping[$szTableType]['DBMAPPINGS'][$szConsFieldId] ) $aNewRow[$szConsFieldId] = $myFieldValue; else $aNewRow[$myFieldName] = $myFieldValue; + */ } // Add new row to result diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index 6dd1177..d4af770 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -326,12 +326,7 @@ class Report_syslogsummary extends Report { $myConsData[SYSLOG_FACILITY] = SYSLOG_LOCAL0; // Set default in this case if (!isset( $content['filter_severity_list'][$myConsData[SYSLOG_SEVERITY]] )) $myConsData[SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case - - // Set Counter and First/Last Event date - $myConsData['FirstOccurrence_Date'] = $myConsData[SYSLOG_DATE]; - $myConsData['LastOccurrence_Date'] = $myConsData[SYSLOG_DATE]; } - } // TimeStats From ea7db9a8392b245855f1b47daa9b542755e13ba3 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 27 Oct 2011 12:34:05 +0200 Subject: [PATCH 08/23] Implemented method to update all checksum values at once in logstream classes Enhanced Syslog logging, if socket functions are available, RFC5424 Syslog messages are generated for better debugging support. --- src/classes/logstream.class.php | 8 +- src/classes/logstreamdb.class.php | 47 ++++- src/classes/logstreamdisk.class.php | 16 ++ src/classes/logstreampdo.class.php | 42 +++++ .../report.syslog.syslogsummary.class.php | 175 +++++++++--------- src/include/functions_common.php | 29 ++- 6 files changed, 226 insertions(+), 91 deletions(-) diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 728562c..7e35211 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -252,6 +252,12 @@ abstract class LogStream { public abstract function SaveMessageChecksum( $arrProperitesIn ); + /* + * Helper function to set the checksum for all messages in the current logstream class + */ + public abstract function UpdateAllMessageChecksum( ); + + /* * Helper function for logstream classes to clear filter based stuff */ @@ -279,7 +285,7 @@ abstract class LogStream { else $finalfilters = $szFilters; - OutputDebugMessage("SetFilter combined = '" . $finalfilters . "'. ", DEBUG_DEBUG); + OutputDebugMessage("LogStream|SetFilter: SetFilter combined = '" . $finalfilters . "'. ", DEBUG_DEBUG); // Reset Filters first to make sure we do not add multiple filters! $this->_filters = null; diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 598ccca..13d54d3 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -601,6 +601,46 @@ class LogStreamDB extends LogStream { return $rowcount; } + + /* + * Implementation of the UpdateAllMessageChecksum + * + * Update all missing checksum properties in the current database + */ + public function UpdateAllMessageChecksum( ) + { + global $querycount, $dbmapping; + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // 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"; + + // Output Debug Informations + OutputDebugMessage("LogStreamDB|UpdateAllMessageChecksum: Running Created SQL Query:
" . $szSql, DEBUG_ULTRADEBUG); + + // Running SQL Query + $myQuery = mysql_query($szSql, $this->_dbhandle); + if ($myQuery) + { + // Debug Output + OutputDebugMessage("LogStreamDB|UpdateAllMessageChecksum: Successfully updated Checksum of '" . mysql_affected_rows($this->_dbhandle) . "' datarecords", DEBUG_INFO); + + // Return success + return SUCCESS; + } + else + { + // error occured, output DEBUG message + $this->PrintDebugError("SaveMessageChecksum failed with SQL Statement ' " . $szSql . " '"); + + // Failed + return ERROR; + } + } + + /* * Implementation of the SaveMessageChecksum * @@ -613,7 +653,7 @@ class LogStreamDB extends LogStream { if ( isset($arrProperitesIn[SYSLOG_UID]) && isset($arrProperitesIn[MISC_CHECKSUM]) && isset($dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM]) ) { - // DELETE DATA NOW! + // UPDATE DATA NOW! $szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName . " SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = " . $arrProperitesIn[MISC_CHECKSUM] . " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_UID] . " = " . $arrProperitesIn[SYSLOG_UID]; @@ -712,6 +752,9 @@ class LogStreamDB extends LogStream { " ORDER BY " . $myDBSortedFieldName . " " . $szSortingOrder . $szLimitSql ; + // Output Debug Informations + OutputDebugMessage("LogStreamDB|ConsolidateItemListByField: Running Created SQL Query:
" . $szSql, DEBUG_ULTRADEBUG); + // Perform Database Query $myquery = mysql_query($szSql, $this->_dbhandle); if ( !$myquery ) @@ -849,7 +892,7 @@ class LogStreamDB extends LogStream { $szLimitSql ; // Output Debug Informations - OutputDebugMessage("LogStreamDB|ConsolidateDataByField: Running Created SQL Query:
" . $szSql, DEBUG_DEBUG); + OutputDebugMessage("LogStreamDB|ConsolidateDataByField: Running Created SQL Query:
" . $szSql, DEBUG_ULTRADEBUG); // Perform Database Query $myquery = mysql_query($szSql, $this->_dbhandle); diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 5568a50..875098a 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -666,6 +666,17 @@ class LogStreamDisk extends LogStream { } + /* + * Implementation of the UpdateAllMessageChecksum + * + * not implemented! + */ + public function UpdateAllMessageChecksum( ) + { + return SUCCESS; + } + + /** * Implementation of ConsolidateItemListByField * @@ -785,6 +796,11 @@ class LogStreamDisk extends LogStream { { if ( isset($logArray[$szConsFieldId]) ) { + // --- Special Case for the checksum field, we need to generate the checksum ourself! + if ( $szConsFieldId == MISC_CHECKSUM ) + $logArray[$szConsFieldId] = crc32( $logArray[SYSLOG_MESSAGE] ); + // --- + if ( $nConsFieldType == FILTER_TYPE_DATE ) { // Convert to FULL Day Date for now! diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index bc4eefb..7cd777b 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -690,6 +690,48 @@ class LogStreamPDO extends LogStream { } + /* + * Implementation of the UpdateAllMessageChecksum + * + * Update all missing checksum properties in the current database + */ + public function UpdateAllMessageChecksum( ) + { + global $querycount, $dbmapping; + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // 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"; + + // Output Debug Informations + OutputDebugMessage("LogStreamPDO|UpdateAllMessageChecksum: Running Created SQL Query:
" . $szSql, DEBUG_ULTRADEBUG); + + // Running SQL Query + $myQuery = $this->_dbhandle->query($szSql); + if ( $myQuery ) + { + // Output Debug Informations + OutputDebugMessage("LogStreamPDO|UpdateAllMessageChecksum: Successfully updated Checksum of '" . $myQuery->rowCount() . "' datarecords", DEBUG_INFO); + + // Free query now + $myQuery->closeCursor(); + + // Return success + return SUCCESS; + } + else + { + // error occured, output DEBUG message + $this->PrintDebugError("UpdateAllMessageChecksum failed with SQL Statement ' " . $szSql . " '"); + + // Failed + return ERROR; + } + } + + /* * Implementation of the SaveMessageChecksum * diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index d4af770..16c0ee4 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -299,13 +299,18 @@ class Report_syslogsummary extends Report { $res = $this->_streamObj->Open( $this->_arrProperties, true ); if ( $res == SUCCESS ) { - if ( true ) - { // --- New Method to consolidate data! // TimeStats $nowtime = microtime_float(); $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + // Update all Checksums first! + $this->_streamObj->UpdateAllMessageChecksum(); + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + foreach ( $arrHosts as $myHost ) { // Set custom filters @@ -333,97 +338,95 @@ class Report_syslogsummary extends Report { $nowtime = microtime_float(); $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; // --- - } - else + +/* + // --- Old Method! + // Init uid helper + $uID = UID_UNKNOWN; + + // Set position to BEGIN of FILE + $this->_streamObj->Sseek($uID, EnumSeek::BOS, 0); + + // Start reading data + $ret = $this->_streamObj->Read($uID, $logArray); + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + + // Found first data record + if ( $ret == SUCCESS ) { - // --- Old Method! - // Init uid helper - $uID = UID_UNKNOWN; + do + { + // Check if Event from host is in our hosts array + if ( in_array($logArray[SYSLOG_HOST], $arrHosts) ) + { + // Set Host Item Basics if not set yet + if ( !isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST]) ) + { + $content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST] = $logArray[SYSLOG_HOST]; + } - // Set position to BEGIN of FILE - $this->_streamObj->Sseek($uID, EnumSeek::BOS, 0); + // Calc checksum + if ( !isset($logArray[MISC_CHECKSUM]) || $logArray[MISC_CHECKSUM] == 0 ) + { + // Calc crc32 from message, we use this as index + $logArray[MISC_CHECKSUM] = crc32( $logArray[SYSLOG_MESSAGE] ); // Maybe useful somewhere else: sprintf( "%u", crc32 ( $logArray[SYSLOG_MESSAGE] )); + $strChecksum = $logArray[MISC_CHECKSUM]; + + // Save calculated Checksum into DB! + $this->_streamObj->SaveMessageChecksum($logArray); + } + else // Get checksum + $strChecksum = $logArray[MISC_CHECKSUM]; + + // Check if entry exists in result array + if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]) ) + { + // Increment counter and set First/Last Event date + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount']++; + + // Set FirstEvent date if necessary! + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'][EVTIME_TIMESTAMP] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; + + // Set LastEvent date if necessary! + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'][EVTIME_TIMESTAMP] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + } + else + { + // Set Basic data entries + if (isset( $content['filter_facility_list'][$logArray[SYSLOG_FACILITY]] )) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = $logArray[SYSLOG_FACILITY]; + else + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = SYSLOG_LOCAL0; // Set default in this case + if (isset( $content['filter_severity_list'][$logArray[SYSLOG_SEVERITY]] )) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY]; + else + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SYSLOGTAG] = $logArray[SYSLOG_SYSLOGTAG]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE]; + + // Set Counter and First/Last Event date + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount'] = 1; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + } + } + + // Get next data record + $ret = $this->_streamObj->ReadNext($uID, $logArray); + } while ( $ret == SUCCESS ); - // Start reading data - $ret = $this->_streamObj->Read($uID, $logArray); - // TimeStats $nowtime = microtime_float(); $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; - - // Found first data record - if ( $ret == SUCCESS ) - { - do - { - // Check if Event from host is in our hosts array - if ( in_array($logArray[SYSLOG_HOST], $arrHosts) ) - { - // Set Host Item Basics if not set yet - if ( !isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST]) ) - { - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST] = $logArray[SYSLOG_HOST]; - } - - // Calc checksum - if ( !isset($logArray[MISC_CHECKSUM]) || $logArray[MISC_CHECKSUM] == 0 ) - { - // Calc crc32 from message, we use this as index - $logArray[MISC_CHECKSUM] = crc32( $logArray[SYSLOG_MESSAGE] ); // Maybe useful somewhere else: sprintf( "%u", crc32 ( $logArray[SYSLOG_MESSAGE] )); - $strChecksum = $logArray[MISC_CHECKSUM]; - - // Save calculated Checksum into DB! - $this->_streamObj->SaveMessageChecksum($logArray); - } - else // Get checksum - $strChecksum = $logArray[MISC_CHECKSUM]; - - // Check if entry exists in result array - if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]) ) - { - // Increment counter and set First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount']++; - - // Set FirstEvent date if necessary! - if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'][EVTIME_TIMESTAMP] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; - - // Set LastEvent date if necessary! - if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'][EVTIME_TIMESTAMP] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; - } - else - { - // Set Basic data entries - if (isset( $content['filter_facility_list'][$logArray[SYSLOG_FACILITY]] )) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = $logArray[SYSLOG_FACILITY]; - else - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_FACILITY] = SYSLOG_LOCAL0; // Set default in this case - if (isset( $content['filter_severity_list'][$logArray[SYSLOG_SEVERITY]] )) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY]; - else - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_SYSLOGTAG] = $logArray[SYSLOG_SYSLOGTAG]; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE]; - - // Set Counter and First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount'] = 1; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; - } - } - - // Get next data record - $ret = $this->_streamObj->ReadNext($uID, $logArray); - } while ( $ret == SUCCESS ); - - // TimeStats - $nowtime = microtime_float(); - $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; - } - else - return $ret; } - + else + return $ret; +*/ // --- Start Postprocessing foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) diff --git a/src/include/functions_common.php b/src/include/functions_common.php index fa90ce3..cbf4fb4 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -570,7 +570,6 @@ function CheckAndSetRunMode() // --- Check necessary PHP Extensions! $loadedExtensions = get_loaded_extensions(); - // Check for GD libary if ( in_array("gd", $loadedExtensions) ) $content['GD_IS_ENABLED'] = true; @@ -581,6 +580,8 @@ function CheckAndSetRunMode() if ( in_array("mysql", $loadedExtensions) ) { $content['MYSQL_IS_ENABLED'] = true; } else { $content['MYSQL_IS_ENABLED'] = false; } // Check PDO Extension if ( in_array("PDO", $loadedExtensions) ) { $content['PDO_IS_ENABLED'] = true; } else { $content['PDO_IS_ENABLED'] = false; } + // Check sockets Extension + if ( in_array("sockets", $loadedExtensions) ) { $content['SOCKETS_IS_ENABLED'] = true; } else { $content['SOCKETS_IS_ENABLED'] = false; } // --- } @@ -1347,7 +1348,31 @@ function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO) // Check if the user wants to syslog the error! if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 ) { - $syslogSend = syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); + if ( $content['SOCKETS_IS_ENABLED'] ) + { + // Send using UDP ourself! + $sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); + $stprifac = (SYSLOG_LOCAL0 << 3); + if ( $szDbgLevel == DEBUG_ERROR_WTF ) + $stprifac += SYSLOG_CRIT; + else if ( $szDbgLevel == DEBUG_ERROR ) + $stprifac += SYSLOG_ERR; + else if ( $szDbgLevel == DEBUG_WARN ) + $stprifac += SYSLOG_WARNING; + else if ( $szDbgLevel == DEBUG_INFO ) + $stprifac += SYSLOG_NOTICE; + else if ( $szDbgLevel == DEBUG_DEBUG ) + $stprifac += SYSLOG_INFO; + else if ( $szDbgLevel == DEBUG_ULTRADEBUG ) + $stprifac += SYSLOG_DEBUG; + + // Generate RFC5424 Syslog MSG + $szsyslogmsg = "<" . $stprifac . ">" . date("c") . " " . php_uname ("n") . " " . "loganalyzer - - - " . $szDbg ; + @socket_sendto($sock, $szsyslogmsg, strlen($szsyslogmsg), 0, '127.0.0.1', 514); + @socket_close($sock); + } + else // Use PHP System function to send via syslog + $syslogSend = syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg); } } From 49aa37721d40bcf91e749e011a46f907fb5ff7e9 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 27 Oct 2011 16:16:51 +0200 Subject: [PATCH 09/23] Enhanced Eventlog Summary Report, it used the new functions to generate the reports --- .../report.eventlog.eventsummary.class.php | 136 ++++++++++++------ ...report.eventlog.eventsummary.template.html | 15 +- .../report.eventlog.eventsummary.template.pdf | 12 +- 3 files changed, 106 insertions(+), 57 deletions(-) diff --git a/src/classes/reports/report.eventlog.eventsummary.class.php b/src/classes/reports/report.eventlog.eventsummary.class.php index 78c052f..cbdc7fc 100644 --- a/src/classes/reports/report.eventlog.eventsummary.class.php +++ b/src/classes/reports/report.eventlog.eventsummary.class.php @@ -296,15 +296,50 @@ class Report_eventsummary extends Report { */ private function ConsolidateEventsPerHost( $arrHosts ) { - global $content, $gl_starttime; + global $content, $gl_starttime, $fields; // Now open the stream for data processing $res = $this->_streamObj->Open( $this->_arrProperties, true ); if ( $res == SUCCESS ) { - // Set reading direction -// $this->_streamObj->SetReadDirection( EnumReadDirection::Backward ); + // --- New Method to consolidate data! + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + // Update all Checksums first! + $this->_streamObj->UpdateAllMessageChecksum(); + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + + foreach ( $arrHosts as $myHost ) + { + // Set custom filters + $this->_streamObj->ResetFilters(); + $this->_streamObj->SetFilter( $this->_filterString . " " . $fields[SYSLOG_MESSAGETYPE]['SearchField'] . ":=" . IUT_NT_EventReport . ",=" . IUT_WEVTMONV2 . " " . $fields[SYSLOG_HOST]['SearchField'] . ":=" . $myHost ); + + // Set Host Item Basics if not set yet + $content["report_consdata"][ $myHost ][SYSLOG_HOST] = $myHost; + + // Get Data for single host + $content["report_consdata"][ $myHost ]['cons_events'] = $this->_streamObj->ConsolidateDataByField( MISC_CHECKSUM, $this->_maxEventsPerHost, MISC_CHECKSUM, SORTING_ORDER_DESC, null, true, true ); + //print_r ($fields[SYSLOG_MESSAGE]); + foreach ( $content["report_consdata"][ $myHost ]['cons_events'] as &$myConsData ) + { + // Set Basic data entries + if (!isset( $content['filter_severity_list'][$myConsData[SYSLOG_SEVERITY]] )) + $myConsData[SYSLOG_SEVERITY] = SYSLOG_NOTICE; // Set default in this case + } + } + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + // --- + +/* OLD CODE // Init uid helper $uID = UID_UNKNOWN; @@ -381,59 +416,74 @@ class Report_eventsummary extends Report { // TimeStats $nowtime = microtime_float(); $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + } +*/ - // Start Postprocessing - foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) + // Start Postprocessing + foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) + { + // First use callback function to sort array + uasort($tmpConsolidatedComputer['cons_events'], "MultiSortArrayByItemCountDesc"); + + // Remove entries according to _maxEventsPerHost + if ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost ) { - // First use callback function to sort array - uasort($tmpConsolidatedComputer['cons_events'], "MultiSortArrayByItemCountDesc"); + $iDropCount = 0; + + do + { + array_pop($tmpConsolidatedComputer['cons_events']); + $iDropCount++; + } while ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost ); - // Remove entries according to _maxEventsPerHost - if ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost ) + // Append a dummy entry which shows count of all other events + if ( $iDropCount > 0 ) { - $iDropCount = 0; + $lastEntry[SYSLOG_SEVERITY] = SYSLOG_NOTICE; + $lastEntry[SYSLOG_EVENT_ID] = "-"; + $lastEntry[SYSLOG_EVENT_SOURCE] = $content['LN_GEN_ALL_OTHER_EVENTS']; + $lastEntry[SYSLOG_MESSAGE] = $content['LN_GEN_ALL_OTHER_EVENTS']; + $lastEntry['ItemCount'] = $iDropCount; + $lastEntry['FirstEvent_Date'] = "-"; + $lastEntry['LastEvent_Date'] = "-"; - do - { - array_pop($tmpConsolidatedComputer['cons_events']); - $iDropCount++; - } while ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost ); - - // Append a dummy entry which shows count of all other events - if ( $iDropCount > 0 ) - { - $lastEntry[SYSLOG_SEVERITY] = SYSLOG_NOTICE; - $lastEntry[SYSLOG_EVENT_ID] = "-"; - $lastEntry[SYSLOG_EVENT_SOURCE] = $content['LN_GEN_ALL_OTHER_EVENTS']; - $lastEntry[SYSLOG_MESSAGE] = $content['LN_GEN_ALL_OTHER_EVENTS']; - $lastEntry['ItemCount'] = $iDropCount; - $lastEntry['FirstEvent_Date'] = "-"; - $lastEntry['LastEvent_Date'] = "-"; - - $tmpConsolidatedComputer['cons_events'][] = $lastEntry; - } - } - - // TimeStats - $nowtime = microtime_float(); - $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; - - // PostProcess Events! - foreach( $tmpConsolidatedComputer["cons_events"] as &$tmpMyEvent ) - { - $tmpMyEvent['FirstEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['FirstEvent_Date'] ); - $tmpMyEvent['LastEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['LastEvent_Date'] ); - $tmpMyEvent['syslogseverity_text'] = $content['filter_severity_list'][ $tmpMyEvent['syslogseverity'] ]["DisplayName"]; + $tmpConsolidatedComputer['cons_events'][] = $lastEntry; } } + + // TimeStats + $nowtime = microtime_float(); + $content["report_rendertime"] .= number_format($nowtime - $gl_starttime, 2, '.', '') . "s "; + + // PostProcess Events! + foreach( $tmpConsolidatedComputer["cons_events"] as &$tmpMyEvent ) + { + $tmpMyEvent['FirstEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['FirstOccurrence_Date'] ); + $tmpMyEvent['LastEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['LastOccurrence_Date'] ); + $tmpMyEvent['syslogseverity_text'] = $content['filter_severity_list'][ $tmpMyEvent['syslogseverity'] ]["DisplayName"]; + $tmpMyEvent['syslogseverity_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogseverity']); + } } - else - return $ret; + // --- } // Work done! return SUCCESS; } + + /* + * Helper function to obtain Severity background color + */ + private function GetSeverityBGColor( $nSeverity ) + { + global $severity_colors; + + if ( isset( $severity_colors[$nSeverity] ) ) + return $severity_colors[$nSeverity]; + else + return $severity_colors[SYSLOG_INFO]; //Default + } + } ?> \ No newline at end of file diff --git a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html index 8796d34..de4bf5a 100644 --- a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html +++ b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html @@ -94,30 +94,29 @@
{ln_report_number}{ln_report_count} {ln_report_firstoccurrence} {ln_report_lastoccurrence} {ln_report_severity} {ln_report_facility} {ln_report_syslogtag}{ln_report_count}
{ZAEHLER}{FirstOccurrence_Date_Formatted}{LastOccurrence_Date_Formatted}{syslogseverity_text}{syslogfacility_text}{syslogtag} {ItemCount} {ItemCount} {FirstOccurrence_Date_Formatted}{LastOccurrence_Date_Formatted}{syslogseverity_text}{syslogfacility_text}{syslogtag}
{ln_report_description}
+ - - - - - - - - + + + + + + diff --git a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf index 0fae148..6392adb 100644 --- a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf +++ b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf @@ -68,27 +68,27 @@
{ln_report_number}{ln_report_count} {ln_report_firstevent} {ln_report_lastevent} {ln_report_process} {ln_report_severity} {ln_report_eventid} {ln_report_description}{ln_report_count}
{ZAEHLER}{FirstEvent_Date_Formatted}{LastEvent_Date_Formatted}{sourceproc}{syslogseverity_text}{id}{msg} {ItemCount} {ItemCount} {FirstEvent_Date_Formatted}{LastEvent_Date_Formatted}{sourceproc}{syslogseverity_text}{id}{msg}
+ - - - - - - + + + + + From 385f14445403514a68c33fac647d9d972cd103ba Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 27 Oct 2011 17:01:46 +0200 Subject: [PATCH 10/23] Cosmetic changes in report templates --- .../report.eventlog.eventsummary.template.html | 2 +- .../report.syslog.syslogsummary.template.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html index de4bf5a..d31ca2d 100644 --- a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html +++ b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html @@ -91,7 +91,7 @@

{FROMHOST}

-
{ln_report_number}{ln_report_count} {ln_report_firstevent} {ln_report_lastevent} {ln_report_process} {ln_report_severity} {ln_report_eventid}{ln_report_count}
{ZAEHLER}{FirstEvent_Date_Formatted}{LastEvent_Date_Formatted}{sourceproc}{syslogseverity_text}{id} {ItemCount} {ItemCount} {FirstEvent_Date_Formatted}{LastEvent_Date_Formatted}{sourceproc}{syslogseverity_text}{id}
{ln_report_description}
+
diff --git a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html index 1587356..4001010 100644 --- a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html +++ b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html @@ -92,7 +92,7 @@

{FROMHOST}

-
{ln_report_number} {ln_report_count}
+
From 44bca08e569ae938173250241f4da6247d010f66 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 28 Oct 2011 19:14:05 +0200 Subject: [PATCH 11/23] Added functions in logstream and report classes to check for INDEXES and TRIGGERS in database logstreams. These function can automatically add INDEXES and TRIGGERS which will improve performance on report generation! --- src/admin/reports.php | 102 ++++++++ src/classes/logstream.class.php | 25 ++ src/classes/logstreamdb.class.php | 224 ++++++++++++++++++ src/classes/reports/report.class.php | 19 ++ .../report.eventlog.eventsummary.class.php | 27 +++ .../report.syslog.syslogsummary.class.php | 136 +++++++++++ src/include/constants_errors.php | 4 + src/lang/en/admin.php | 13 + src/templates/admin/admin_reports.html | 27 +++ 9 files changed, 577 insertions(+) diff --git a/src/admin/reports.php b/src/admin/reports.php index 54e7427..f1bc3e2 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -358,6 +358,9 @@ if ( isset($_GET['op']) ) $mySource['sourceselected'] = ""; } + // Check if logstream is optimized! + CheckConfiguredLogStreamSource($myReport, $content['SourceID']); + // Create Outputlist $content['outputFormat'] = REPORT_OUTPUT_HTML; CreateOutputformatList( $content['outputFormat'] ); @@ -447,6 +450,9 @@ if ( isset($_GET['op']) ) $mySource['sourceselected'] = ""; } + // Check if logstream is optimized! + CheckConfiguredLogStreamSource($myReport, $content['SourceID']); + // Create Outputlist $content['outputFormat'] = $mySavedReport['outputFormat']; CreateOutputformatList( $content['outputFormat'] ); @@ -1236,6 +1242,102 @@ $page -> output(); // --- // --- BEGIN Helper functions // --- + +/* +* Helper function to init custom filters from report +*/ +function CheckConfiguredLogStreamSource($myReport, $mySourceID) +{ + global $content, $extraErrorDescription; + + // Get Objectreference to report + $myReportObj = $myReport["ObjRef"]; + + // Check if optimize variable is set! + if ( isset($_GET['optimize']) ) + { + // Check what we have to do + if ( $_GET['optimize'] == "indexes" ) + { + // This will create all INDEXES we need for this logstream! + $res = $myReportObj->CreateLogStreamIndexes( $mySourceID ); + if ( $res != SUCCESS ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_FAILED_CREATE_INDEXES'], $content['SOURCES'][$mySourceID]['Name'], $res ); + if ( isset($extraErrorDescription) ) + $content['ERROR_MSG'] .= "

" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription); + } + + // Show information in performance warning area + $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_SUBMITFORM'] = "false"; + + // return result + return $res; + } + else if ( $_GET['optimize'] == "trigger" ) + { + // This will create all INDEXES we need for this logstream! + $res = $myReportObj->CreateLogStreamTrigger( $mySourceID ); + if ( $res != SUCCESS ) + { + $content['ISERROR'] = true; + $content['ERROR_MSG'] = GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_FAILED_CREATE_TRIGGER'], $content['SOURCES'][$mySourceID]['Name'], $res ); + if ( isset($extraErrorDescription) ) + $content['ERROR_MSG'] .= "

" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription); + } + + // Show information in performance warning area + $content['ISSOURCENOTOPTIMIZED'] = true; + $content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_TRIGGER_CREATED']; + $content['MSG_WARNING_CLASS'] = 'PriorityNotice'; + $content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_TRIGGER_CREATED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] ); + $content['MSG_WARNING_SUBMITFORM'] = "false"; + + // return result + return $res; + } + } + + $res = $myReportObj->CheckLogStreamSource( $mySourceID ); + if ( $res != SUCCESS ) + { + // Handle GET and POST input! + $content['MSG_WARNING_FORMURL'] = $_SERVER['SCRIPT_NAME'] . "?"; + foreach ($_GET as $varname => $varvalue) + $content['MSG_WARNING_FORMURL'] .= $varname . "=" . $varvalue . "&"; + foreach ($_POST as $varname => $varvalue) + $content['POST_VARIABLES'][] = array( "varname" => $varname, "varvalue" => $varvalue ); + + // Current Logstream Source is not optimized! Show to user! + $content['ISSOURCENOTOPTIMIZED'] = true; + 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! + } + else if ( $res == ERROR_DB_TRIGGERMISSING ) + { + $content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_PERFORMANCE_WARNING']; + $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! + } + } +} + + +/* +* Helper function to init custom filters from report +*/ function InitCustomFilterDefinitions($myReport, $CustomFilterValues) { global $content; diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 7e35211..9a78fec 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -263,6 +263,31 @@ abstract class LogStream { */ public abstract function ResetFilters( ); + + /* + * Helper function for logstream classes to check for data indexes, only applies to database based logstream classes + */ + public abstract function VerifyIndexes( $arrProperitesIn ); + + + /* + * Helper function for logstream classes to create missing indexes, only applies to database based logstream classes + */ + public abstract function CreateMissingIndexes( $arrProperitesIn ); + + + /* + * Helper function for logstream classes to check for missing triggers, only applies to database based logstream classes + */ + public abstract function VerifyChecksumTrigger( ); + + + /* + * Helper function for logstream classes to create missing trigger, only applies to database based logstream classes + */ + public abstract function CreateMissingTrigger( ); + + /* * Helper functino to trigger initialisation of MsgParsers */ diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 13d54d3..3249297 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -181,6 +181,152 @@ class LogStreamDB extends LogStream { return SUCCESS; } + + /* + * Implementation of VerifyIndexes: Checks if indexes exist for desired fields + */ + public function VerifyIndexes( $arrProperitesIn ) + { + global $dbmapping, $fields; + + // Get List of Indexes as Array + $arrIndexKeys = $this->GetIndexesAsArray(); + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // Loop through all fields to see which one is missing! + foreach ( $arrProperitesIn as $myproperty ) + { +// echo $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "
"; + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrIndexKeys) ) + { + OutputDebugMessage("LogStreamDB|VerifyIndexes: Found INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG); + continue; + } + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamDB|VerifyIndexes: Missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_WARN); + return ERROR_DB_INDEXESMISSING; + } + } + + // Successfull + return SUCCESS; + } + + + /* + * Implementation of VerifyChecksumTrigger: Checks if checksum trigger exists + */ + public function VerifyChecksumTrigger( ) + { + global $dbmapping, $fields; + + // Get List of Triggers as Array + $arrIndexTriggers = $this->GetTriggersAsArray(); + $szDBName = $this->_logStreamConfigObj->DBName; + + $szTableName = $this->_logStreamConfigObj->DBTableName; + $szTriggerName = $szDBName . "_" . $szTableName; + + // Try to find logstream trigger + if ( count($arrIndexTriggers) > 0 ) + { + if ( in_array($szTriggerName, $arrIndexTriggers) ) + return SUCCESS; + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamDB|VerifyChecksumTrigger: Missing TRIGGERS for Table '" . $szTableName . "'", DEBUG_WARN); + return ERROR_DB_TRIGGERMISSING; + } + } + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamDB|VerifyChecksumTrigger: No TRIGGERS found in your database", DEBUG_WARN); + return ERROR_DB_TRIGGERMISSING; + } + } + + + /* + * Implementation of CreateMissingIndexes: Checks if indexes exist for desired fields + */ + public function CreateMissingIndexes( $arrProperitesIn ) + { + global $dbmapping, $fields, $querycount; + + // Get List of Indexes as Array + $arrIndexKeys = $this->GetIndexesAsArray(); + $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], $arrIndexKeys) ) + continue; + else + { + // Update Table schema now! + $szSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD INDEX ( " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " )"; + + // Index is missing for this field! + OutputDebugMessage("LogStreamDB|CreateMissingIndexes: Createing missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' - " . $szSql, DEBUG_INFO); + + // Add missing INDEX now! + $myQuery = mysql_query($szSql, $this->_dbhandle); + if (!$myQuery) + { + // Return failure! + $this->PrintDebugError("Dynamically Adding INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' failed with Statement: '" . $szSql . "'"); + return ERROR_DB_INDEXFAILED; + } + } + } + + // Successfull + return SUCCESS; + } + + + /* + * Implementation of CreateMissingTrigger: Checks if indexes exist for desired fields + */ + public function CreateMissingTrigger( ) + { + global $dbmapping, $fields, $querycount; + + // Get List of Triggers as Array + $szDBName = $this->_logStreamConfigObj->DBName; + $szTableName = $this->_logStreamConfigObj->DBTableName; + $szTriggerName = $szDBName . "_" . $szTableName; + + // Create TRIGGER SQL! + $szSql = "CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT ON `" . $szTableName . "` + FOR EACH ROW + BEGIN + SET NEW.Checksum = crc32(NEW.Message); + END + ;"; + + // Index is missing for this field! + OutputDebugMessage("LogStreamDB|CreateMissingTrigger: Createing missing TRIGGER for '" . $szTableName . "' - " . $szSql, DEBUG_INFO); + + // Add missing INDEX now! + $myQuery = mysql_query($szSql, $this->_dbhandle); + if (!$myQuery) + { + // Return failure! + $this->PrintDebugError("Dynamically Adding TRIGGER for '" . $szTableName . "' failed with Statement: '" . $szSql . "'"); + return ERROR_DB_TRIGGERFAILED; + } + + // Successfull + return SUCCESS; + } + + /** * Read the data from a specific uID which means in this * case beginning with from the Database ID @@ -1586,6 +1732,84 @@ class LogStreamDB extends LogStream { return ERROR_DB_DBFIELDNOTFOUND; } + /* + * Helper function to return a list of Indexes for the logstream table + */ + private function GetIndexesAsArray() + { + global $querycount; + + // Verify database connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; + + // Init Array + $arrIndexKeys = array(); + + // Create SQL and Get INDEXES for table! + $szSql = "SHOW INDEX FROM " . $this->_logStreamConfigObj->DBTableName; + $myQuery = mysql_query($szSql, $this->_dbhandle); + if ($myQuery) + { + // Loop through results + while ($myRow = mysql_fetch_array($myQuery, MYSQL_ASSOC)) + { + // Add to index keys + $arrIndexKeys[] = strtolower($myRow['Key_name']); + } + + // Free query now + mysql_free_result ($myQuery); + + // Increment for the Footer Stats + $querycount++; + } + + // return Array + return $arrIndexKeys; + } + + + /* + * Helper function to return a list of Indexes for the logstream table + */ + private function GetTriggersAsArray() + { + global $querycount; + + // Verify database connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; + + // Init Array + $arrIndexTriggers = array(); + + // Create SQL and Get INDEXES for table! + $szSql = "SHOW TRIGGERS"; + $myQuery = mysql_query($szSql, $this->_dbhandle); + if ($myQuery) + { + // Loop through results + while ($myRow = mysql_fetch_array($myQuery, MYSQL_ASSOC)) + { +// print_r ( $myRow ); + // Add to index keys + $arrIndexTriggers[] = strtolower($myRow['Trigger']); + } + + // Free query now + mysql_free_result ($myQuery); + + // Increment for the Footer Stats + $querycount++; + } + + // return Array + return $arrIndexTriggers; + } + // --- End of Class! } diff --git a/src/classes/reports/report.class.php b/src/classes/reports/report.class.php index 75c3e6e..7ba8ad2 100644 --- a/src/classes/reports/report.class.php +++ b/src/classes/reports/report.class.php @@ -117,6 +117,25 @@ abstract class Report { */ public abstract function InitAdvancedSettings(); + + /** + * If the reports needs to optimize the logstream, it is checked and verified by this function + */ + public abstract function CheckLogStreamSource( $mySourceID ); + + + /** + * If the reports needs INDEXES, these are created by this function + */ + public abstract function CreateLogStreamIndexes( $mySourceID ); + + + /** + * If the reports needs a TRIGGER, these are created by this function + */ + public abstract function CreateLogStreamTrigger( $mySourceID ); + + /** * verifyDataSource, verifies if data is accessable and * contains what we need diff --git a/src/classes/reports/report.eventlog.eventsummary.class.php b/src/classes/reports/report.eventlog.eventsummary.class.php index cbdc7fc..69e531b 100644 --- a/src/classes/reports/report.eventlog.eventsummary.class.php +++ b/src/classes/reports/report.eventlog.eventsummary.class.php @@ -289,6 +289,33 @@ class Report_eventsummary extends Report { } + /* + * Implementation of CheckLogStreamSource + */ + public function CheckLogStreamSource( $mySourceID ) + { + + + } + + + /* + * Implementation of CreateLogStreamIndexes | Will create missing INDEXES + */ + public function CreateLogStreamIndexes( $mySourceID ) + { + + } + + + /* + * Implementation of CreateLogStreamIndexes | Will create missing TRIGGER + */ + public function CreateLogStreamTrigger( $mySourceID ) + { + + } + // --- Private functions... /** diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index 16c0ee4..c79d7a2 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -286,6 +286,142 @@ class Report_syslogsummary extends Report { } + /* + * Implementation of CheckLogStreamSource + */ + public function CheckLogStreamSource( $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 check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->VerifyIndexes( array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY) ); + if ($res != SUCCESS ) + return $res; + + // Will check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->VerifyChecksumTrigger(); + if ($res != SUCCESS ) + return $res; + } + + // return results! + return $res; + } + + + /* + * Implementation of CreateLogStreamIndexes | Will create missing INDEXES + */ + public function CreateLogStreamIndexes( $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 check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->CreateMissingIndexes( array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY) ); + if ($res != SUCCESS ) + return $res; + } + + // return results! + return $res; + } + + + /* + * Implementation of CreateLogStreamIndexes | Will create missing INDEXES + */ + public function CreateLogStreamTrigger( $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 check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->CreateMissingTrigger(); + if ($res != SUCCESS ) + return $res; + } + + // return results! + return $res; + } + // --- Private functions... /** diff --git a/src/include/constants_errors.php b/src/include/constants_errors.php index 7669c1e..64e5900 100644 --- a/src/include/constants_errors.php +++ b/src/include/constants_errors.php @@ -67,5 +67,9 @@ define('ERROR_CHARTS_NOTCONFIGURED', 20); define('ERROR_MSG_SKIPMESSAGE', 21); define('ERROR_MSG_SCANABORTED', 23); define('ERROR_REPORT_NODATA', 25); +define('ERROR_DB_INDEXESMISSING', 26); +define('ERROR_DB_TRIGGERMISSING', 27); +define('ERROR_DB_INDEXFAILED', 28); +define('ERROR_DB_TRIGGERFAILED', 29); ?> \ No newline at end of file diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index e0e2eb6..1497c22 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -457,6 +457,19 @@ $content['LN_REPORTS_NOTINSTALLED'] = "Not installed"; $content['LN_REPORTS_DOWNLOAD'] = "Download Link"; $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.

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_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.

Do you want LogAnalyter 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_'] = ""; $content['LN_REPORTS_'] = ""; + + ?> \ No newline at end of file diff --git a/src/templates/admin/admin_reports.html b/src/templates/admin/admin_reports.html index 8014aeb..2c5a994 100644 --- a/src/templates/admin/admin_reports.html +++ b/src/templates/admin/admin_reports.html @@ -270,6 +270,33 @@ + +
{ln_report_number} {ln_report_count}
+ + + + + + + + +
+
{MSG_WARNING_TITLE}
+

{MSG_WARNING_DETAILS}

+
+
+
+ + + + +
+ +
+ +
+ +
From 911e0f4a7002955c349a304245460cfde0f11f43 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Mon, 31 Oct 2011 17:44:53 +0100 Subject: [PATCH 12/23] Added functions to automatically add triggers and change the checksum field to int unsigned This change will also be important for the new reporting engine --- src/admin/reports.php | 16 +- src/classes/logstream.class.php | 4 +- src/classes/logstreamdb.class.php | 96 ++++++++++-- src/classes/reports/report.class.php | 138 ++++++++++++++++++ .../report.eventlog.eventsummary.class.php | 13 +- .../report.syslog.syslogsummary.class.php | 110 +------------- src/include/constants_errors.php | 3 + 7 files changed, 256 insertions(+), 124 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index f1bc3e2..73ec709 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -1290,13 +1290,15 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID) if ( isset($extraErrorDescription) ) $content['ERROR_MSG'] .= "

" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription); } - - // Show information in performance warning area - $content['ISSOURCENOTOPTIMIZED'] = true; - $content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_TRIGGER_CREATED']; - $content['MSG_WARNING_CLASS'] = 'PriorityNotice'; - $content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_TRIGGER_CREATED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] ); - $content['MSG_WARNING_SUBMITFORM'] = "false"; + else + { + // Show information in performance warning area + $content['ISSOURCENOTOPTIMIZED'] = true; + $content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_TRIGGER_CREATED']; + $content['MSG_WARNING_CLASS'] = 'PriorityNotice'; + $content['MSG_WARNING_DETAILS'] = GetAndReplaceLangStr( $content['LN_REPORTS_TRIGGER_CREATED_SUCCESS'], $content['SOURCES'][$mySourceID]['Name'] ); + $content['MSG_WARNING_SUBMITFORM'] = "false"; + } // return result return $res; diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index 9a78fec..dd8679a 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -279,13 +279,13 @@ abstract class LogStream { /* * Helper function for logstream classes to check for missing triggers, only applies to database based logstream classes */ - public abstract function VerifyChecksumTrigger( ); + public abstract function VerifyChecksumTrigger( $myTriggerProperty ); /* * Helper function for logstream classes to create missing trigger, only applies to database based logstream classes */ - public abstract function CreateMissingTrigger( ); + public abstract function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty ); /* diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 3249297..eae0cd5 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -218,16 +218,20 @@ class LogStreamDB extends LogStream { /* * Implementation of VerifyChecksumTrigger: Checks if checksum trigger exists */ - public function VerifyChecksumTrigger( ) + public function VerifyChecksumTrigger( $myTriggerProperty ) { global $dbmapping, $fields; // Get List of Triggers as Array $arrIndexTriggers = $this->GetTriggersAsArray(); + + $szTableType = $this->_logStreamConfigObj->DBTableType; $szDBName = $this->_logStreamConfigObj->DBName; - $szTableName = $this->_logStreamConfigObj->DBTableName; - $szTriggerName = $szDBName . "_" . $szTableName; + $szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty]; + + // Create Triggername + $szTriggerName = $szDBName . "_" . $szTableName . "_" . $szDBTriggerField; // Try to find logstream trigger if ( count($arrIndexTriggers) > 0 ) @@ -237,7 +241,7 @@ class LogStreamDB extends LogStream { else { // Index is missing for this field! - OutputDebugMessage("LogStreamDB|VerifyChecksumTrigger: Missing TRIGGERS for Table '" . $szTableName . "'", DEBUG_WARN); + OutputDebugMessage("LogStreamDB|VerifyChecksumTrigger: Missing TRIGGER '" . $szTriggerName . "' for Table '" . $szTableName . "'", DEBUG_WARN); return ERROR_DB_TRIGGERMISSING; } } @@ -293,25 +297,30 @@ class LogStreamDB extends LogStream { /* * Implementation of CreateMissingTrigger: Checks if indexes exist for desired fields */ - public function CreateMissingTrigger( ) + 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; - $szTriggerName = $szDBName . "_" . $szTableName; + $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.Checksum = crc32(NEW.Message); + SET NEW." . $szDBTriggerCheckSumField . " = crc32(NEW." . $szDBTriggerField . "); END ;"; // Index is missing for this field! - OutputDebugMessage("LogStreamDB|CreateMissingTrigger: Createing missing TRIGGER for '" . $szTableName . "' - " . $szSql, DEBUG_INFO); + OutputDebugMessage("LogStreamDB|CreateMissingTrigger: Creating missing TRIGGER for '" . $szTableName . "' - $szDBTriggerCheckSumField = crc32(NEW.$szDBTriggerField)" . $szSql, DEBUG_INFO); // Add missing INDEX now! $myQuery = mysql_query($szSql, $this->_dbhandle); @@ -1696,9 +1705,14 @@ class LogStreamDB extends LogStream { if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && $errOutArr[1] == $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] ) { // Create SQL Numeric field - $szUpdateSql = ""; + $szUpdateSql = ""; $szUnsigned = ""; if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER ) - $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) NOT NULL DEFAULT '0'"; + { + // 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 ) @@ -1771,6 +1785,68 @@ class LogStreamDB extends LogStream { } + /* + * Helper function to chang ethe checksum field type to unsigned INT! + */ + private function ChangeChecksumFieldUnsigned() + { + global $dbmapping, $fields, $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; + + // Init Array + $arrFields = array(); + + // 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($myRow, "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; + } + + /* * Helper function to return a list of Indexes for the logstream table */ diff --git a/src/classes/reports/report.class.php b/src/classes/reports/report.class.php index 7ba8ad2..7329c6e 100644 --- a/src/classes/reports/report.class.php +++ b/src/classes/reports/report.class.php @@ -656,5 +656,143 @@ abstract class Report { return $res; } + + /** + * If the reports needs to optimize the logstream, it is checked and verified by this function + */ + public function CheckLogStreamSourceByPropertyArray( $mySourceID, $arrProperties, $myTriggerProperty ) + { + 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 check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->VerifyIndexes( $arrProperties ); + if ($res != SUCCESS ) + return $res; + + // Will check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->VerifyChecksumTrigger( $myTriggerProperty ); + if ($res != SUCCESS ) + return $res; + } + + // return results! + return $res; + } + + + /** + * If the reports needs INDEXES, these are created by this function + */ + public function CreateLogStreamIndexesByPropertyArray( $mySourceID, $arrProperties ) + { + 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 check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->CreateMissingIndexes( $arrProperties ); + if ($res != SUCCESS ) + return $res; + } + + // return results! + return $res; + } + + + /** + * If the reports needs INDEXES, these are created by this function + */ + public function CreateLogStreamTriggerByPropertyArray( $mySourceID, $myTriggerProperty, $myChecksumProperty ) + { + 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 check if certain INDEXES do exists for database logstream classes! + $res = $this->_streamObj->CreateMissingTrigger( $myTriggerProperty, $myChecksumProperty ); + if ($res != SUCCESS ) + return $res; + } + + // return results! + return $res; + } + + } ?> \ No newline at end of file diff --git a/src/classes/reports/report.eventlog.eventsummary.class.php b/src/classes/reports/report.eventlog.eventsummary.class.php index 69e531b..062e9f7 100644 --- a/src/classes/reports/report.eventlog.eventsummary.class.php +++ b/src/classes/reports/report.eventlog.eventsummary.class.php @@ -294,8 +294,11 @@ class Report_eventsummary extends Report { */ public function CheckLogStreamSource( $mySourceID ) { + // Call basic report Check function + $res = $this->CheckLogStreamSourceByPropertyArray( $mySourceID, array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY, SYSLOG_MESSAGETYPE), SYSLOG_MESSAGE ); - + // return results! + return $res; } @@ -304,7 +307,11 @@ class Report_eventsummary extends Report { */ public function CreateLogStreamIndexes( $mySourceID ) { + // Call basic report Check function + $res = $this->CreateLogStreamIndexesByPropertyArray( $mySourceID, array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY, SYSLOG_MESSAGETYPE) ); + // return results! + return $res; } @@ -313,7 +320,11 @@ class Report_eventsummary extends Report { */ public function CreateLogStreamTrigger( $mySourceID ) { + // Call basic report Check function + $res = $this->CreateLogStreamTriggerByPropertyArray( $mySourceID, SYSLOG_MESSAGE, MISC_CHECKSUM ); + // return results! + return $res; } diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index c79d7a2..31bbcf7 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -291,44 +291,8 @@ class Report_syslogsummary extends Report { */ public function CheckLogStreamSource( $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 check if certain INDEXES do exists for database logstream classes! - $res = $this->_streamObj->VerifyIndexes( array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY) ); - if ($res != SUCCESS ) - return $res; - - // Will check if certain INDEXES do exists for database logstream classes! - $res = $this->_streamObj->VerifyChecksumTrigger(); - if ($res != SUCCESS ) - return $res; - } + // Call basic report Check function + $res = $this->CheckLogStreamSourceByPropertyArray( $mySourceID, array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY, SYSLOG_MESSAGETYPE), SYSLOG_MESSAGE ); // return results! return $res; @@ -340,39 +304,8 @@ class Report_syslogsummary extends Report { */ public function CreateLogStreamIndexes( $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 check if certain INDEXES do exists for database logstream classes! - $res = $this->_streamObj->CreateMissingIndexes( array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY) ); - if ($res != SUCCESS ) - return $res; - } + // Call basic report Check function + $res = $this->CreateLogStreamIndexesByPropertyArray( $mySourceID, array(SYSLOG_HOST, MISC_CHECKSUM, SYSLOG_DATE, SYSLOG_SEVERITY, SYSLOG_MESSAGETYPE) ); // return results! return $res; @@ -384,39 +317,8 @@ class Report_syslogsummary extends Report { */ public function CreateLogStreamTrigger( $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 check if certain INDEXES do exists for database logstream classes! - $res = $this->_streamObj->CreateMissingTrigger(); - if ($res != SUCCESS ) - return $res; - } + // Call basic report Check function + $res = $this->CreateLogStreamTriggerByPropertyArray( $mySourceID, SYSLOG_MESSAGE, MISC_CHECKSUM ); // return results! return $res; diff --git a/src/include/constants_errors.php b/src/include/constants_errors.php index 64e5900..583909f 100644 --- a/src/include/constants_errors.php +++ b/src/include/constants_errors.php @@ -71,5 +71,8 @@ define('ERROR_DB_INDEXESMISSING', 26); define('ERROR_DB_TRIGGERMISSING', 27); define('ERROR_DB_INDEXFAILED', 28); define('ERROR_DB_TRIGGERFAILED', 29); +define('ERROR_DB_CHECKSUMERROR', 30); +define('ERROR_DB_CHECKSUMCHANGEFAILED', 31); + ?> \ No newline at end of file From 6b6724ab000ba0aeff016c7599bbea62a33f1e95 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 2 Nov 2011 16:16:25 +0100 Subject: [PATCH 13/23] added support for automtaically adding missing fields into logstreamdb for reports. Earlier this was only possible on the main loganalyzer index site --- src/admin/reports.php | 73 +++++- src/classes/logstream.class.php | 29 +++ src/classes/logstreamdb.class.php | 337 +++++++++++++++++-------- src/classes/reports/report.class.php | 104 +++++++- src/include/constants_errors.php | 2 +- src/lang/en/admin.php | 16 +- src/templates/admin/admin_reports.html | 2 +- 7 files changed, 449 insertions(+), 114 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index 73ec709..416c7c7 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -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'] .= "

" . 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'] .= "

" . 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! } } } diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index dd8679a..bc42924 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -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 */ diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index eae0cd5..e515fa1 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -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] . "
"; + 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,30 +328,84 @@ 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]; + + // Get SQL Code to create the trigger! + $szSql = $this->GetCreateMissingTriggerSQL( $szDBTriggerField, $szDBTriggerCheckSumField ); - // 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 - ;"; - // 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!

If you want to manually add the TRIGGER, use the following SQL Command:
" . str_replace("\n", "
", $szSql) . "
"); + 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:
" . $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; - - // 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; + global $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 @@ -1841,9 +1980,9 @@ class LogStreamDB extends LogStream { // Increment for the Footer Stats $querycount++; } - - // return results - return SUCCESS; + + // return Array + return $arrFieldKeys; } diff --git a/src/classes/reports/report.class.php b/src/classes/reports/report.class.php index 7329c6e..a84f799 100644 --- a/src/classes/reports/report.class.php +++ b/src/classes/reports/report.class.php @@ -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; + } + + } ?> \ No newline at end of file diff --git a/src/include/constants_errors.php b/src/include/constants_errors.php index 583909f..0d5f145 100644 --- a/src/include/constants_errors.php +++ b/src/include/constants_errors.php @@ -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); ?> \ No newline at end of file diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index 1497c22..a2eb8fd 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -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.

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.

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.

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.

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!

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.

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_'] = ""; - - ?> \ No newline at end of file diff --git a/src/templates/admin/admin_reports.html b/src/templates/admin/admin_reports.html index 2c5a994..e8d2a0b 100644 --- a/src/templates/admin/admin_reports.html +++ b/src/templates/admin/admin_reports.html @@ -5,7 +5,7 @@
{LN_GEN_ERRORDETAILS}
-

{ERROR_MSG}

+

{ERROR_MSG}



{LN_GEN_ERRORRETURNPREV} From f086f6ec3ee8560ddfe3bc5184b436f4eeae25c9 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 2 Nov 2011 16:41:06 +0100 Subject: [PATCH 14/23] Added missing functions into disk logstream source --- src/classes/logstreamdisk.class.php | 98 ++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 7 deletions(-) diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 875098a..cb1af2d 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -92,13 +92,6 @@ class LogStreamDisk extends LogStream { return SUCCESS; } - /* - * Helper function to clear the current querystring! - */ - public function ResetFilters() - { - // nothing todo in this logstream - } /** * Close the file. @@ -677,6 +670,97 @@ class LogStreamDisk extends LogStream { } + /* + * Helper function to clear the current querystring! + */ + public function ResetFilters() + { + // nothing todo in this logstream + return SUCCESS; + } + + + /* + * Helper function to verify fields | not needed in disk logstream! + */ + public abstract function VerifyFields( $arrProperitesIn ) + { + return SUCCESS; + } + + + /* + * Helper function to create missing fields | not needed in disk logstream! + */ + public abstract function CreateMissingFields( $arrProperitesIn ) + { + return SUCCESS; + } + + + /* + * Helper function to verify indexes | not needed in disk logstream! + */ + public abstract function VerifyIndexes( $arrProperitesIn ) + { + return SUCCESS; + } + + + /* + * Helper function to create missing indexes | not needed in disk logstream! + */ + public abstract function CreateMissingIndexes( $arrProperitesIn ) + { + return SUCCESS; + } + + + /* + * Helper function to verify triggers | not needed in disk logstream! + */ + public abstract function VerifyChecksumTrigger( $myTriggerProperty ) + { + return SUCCESS; + } + + + /* + * Helper function to verify triggers | not needed in disk logstream! + */ + public abstract function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty ) + { + return SUCCESS; + } + + + /* + * Helper function to create missing triggers | not needed in disk logstream! + */ + public abstract function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField ) + { + return SUCCESS; + } + + + /* + * Helper function to verify checksum field | not needed in disk logstream! + */ + public abstract function VerifyChecksumField( ) + { + return SUCCESS; + } + + + /* + * Helper function to correct the checksum field | not needed in disk logstream! + */ + public abstract function ChangeChecksumFieldUnsigned( ) + { + return SUCCESS; + } + + /** * Implementation of ConsolidateItemListByField * From db9fc29da19be2ce65453d722d73385e85ddadbb Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 3 Nov 2011 16:02:55 +0100 Subject: [PATCH 15/23] Implemented missing new logstream functions into logstreamPDO Class --- src/admin/reports.php | 22 +- src/classes/logstreamconfigpdo.class.php | 29 ++ src/classes/logstreamdb.class.php | 3 - src/classes/logstreamdisk.class.php | 19 +- src/classes/logstreampdo.class.php | 564 ++++++++++++++++++++--- src/lang/en/admin.php | 2 + src/templates/admin/admin_reports.html | 3 + 7 files changed, 569 insertions(+), 73 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index 416c7c7..3cbf8c9 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -1253,6 +1253,21 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID) // Get Objectreference to report $myReportObj = $myReport["ObjRef"]; + // Handle GET and POST input! + $content['MSG_WARNING_FORMURL'] = $_SERVER['SCRIPT_NAME'] . "?"; + $content['MSG_CHECK_URL'] = $_SERVER['SCRIPT_NAME'] . "?"; + foreach ($_GET as $varname => $varvalue) + { + // All variables! + $content['MSG_WARNING_FORMURL'] .= $varname . "=" . $varvalue . "&"; + + // Skip the Optimize variable! + if (strpos( $varname, "optimize" ) === false ) + $content['MSG_CHECK_URL'] .= $varname . "=" . $varvalue . "&"; + } + foreach ($_POST as $varname => $varvalue) + $content['POST_VARIABLES'][] = array( "varname" => $varname, "varvalue" => $varvalue ); + // Check if optimize variable is set! if ( isset($_GET['optimize']) ) { @@ -1355,13 +1370,6 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID) $res = $myReportObj->CheckLogStreamSource( $mySourceID ); if ( $res != SUCCESS ) { - // Handle GET and POST input! - $content['MSG_WARNING_FORMURL'] = $_SERVER['SCRIPT_NAME'] . "?"; - foreach ($_GET as $varname => $varvalue) - $content['MSG_WARNING_FORMURL'] .= $varname . "=" . $varvalue . "&"; - foreach ($_POST as $varname => $varvalue) - $content['POST_VARIABLES'][] = array( "varname" => $varname, "varvalue" => $varvalue ); - // Current Logstream Source is not optimized! Show to user! $content['ISSOURCENOTOPTIMIZED'] = true; if ( $res == ERROR_DB_DBFIELDNOTFOUND ) diff --git a/src/classes/logstreamconfigpdo.class.php b/src/classes/logstreamconfigpdo.class.php index 669c8a3..223d59c 100644 --- a/src/classes/logstreamconfigpdo.class.php +++ b/src/classes/logstreamconfigpdo.class.php @@ -64,6 +64,35 @@ class LogStreamConfigPDO extends LogStreamConfig { return new LogStreamPDO($o); } + + public function GetPDOTriggersSupported() + { + // TRIGGERS are not supported for all db engines! + switch ($this->DBType) + { + case DB_MYSQL: + return true; + case DB_MSSQL: + return true; + case DB_ODBC: + return false; + case DB_PGSQL: + return true; + case DB_OCI: + return false; + case DB_DB2: + return false; + case DB_FIREBIRD: + return false; + case DB_INFORMIX: + return false; + case DB_SQLITE: + return false; + default: + return false; + } + } + public function GetPDODatabaseType() { switch ($this->DBType) diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index e515fa1..2e18592 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -967,9 +967,6 @@ class LogStreamDB extends LogStream { $myQuery = mysql_query($szSql, $this->_dbhandle); if ($myQuery) { - // Free res! - // NOT NEEDED HERE! mysql_free_result($myQuery); - // Return success return SUCCESS; } diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index cb1af2d..f127a75 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -613,7 +613,6 @@ class LogStreamDisk extends LogStream { public function GetLogStreamStats() { // Get some file data! - /* // return results! return $stats; @@ -683,7 +682,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to verify fields | not needed in disk logstream! */ - public abstract function VerifyFields( $arrProperitesIn ) + public function VerifyFields( $arrProperitesIn ) { return SUCCESS; } @@ -692,7 +691,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to create missing fields | not needed in disk logstream! */ - public abstract function CreateMissingFields( $arrProperitesIn ) + public function CreateMissingFields( $arrProperitesIn ) { return SUCCESS; } @@ -701,7 +700,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to verify indexes | not needed in disk logstream! */ - public abstract function VerifyIndexes( $arrProperitesIn ) + public function VerifyIndexes( $arrProperitesIn ) { return SUCCESS; } @@ -710,7 +709,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to create missing indexes | not needed in disk logstream! */ - public abstract function CreateMissingIndexes( $arrProperitesIn ) + public function CreateMissingIndexes( $arrProperitesIn ) { return SUCCESS; } @@ -719,7 +718,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to verify triggers | not needed in disk logstream! */ - public abstract function VerifyChecksumTrigger( $myTriggerProperty ) + public function VerifyChecksumTrigger( $myTriggerProperty ) { return SUCCESS; } @@ -728,7 +727,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to verify triggers | not needed in disk logstream! */ - public abstract function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty ) + public function CreateMissingTrigger( $myTriggerProperty, $myCheckSumProperty ) { return SUCCESS; } @@ -737,7 +736,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to create missing triggers | not needed in disk logstream! */ - public abstract function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField ) + public function GetCreateMissingTriggerSQL( $myDBTriggerField, $myDBTriggerCheckSumField ) { return SUCCESS; } @@ -746,7 +745,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to verify checksum field | not needed in disk logstream! */ - public abstract function VerifyChecksumField( ) + public function VerifyChecksumField( ) { return SUCCESS; } @@ -755,7 +754,7 @@ class LogStreamDisk extends LogStream { /* * Helper function to correct the checksum field | not needed in disk logstream! */ - public abstract function ChangeChecksumFieldUnsigned( ) + public function ChangeChecksumFieldUnsigned( ) { return SUCCESS; } diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 7cd777b..2752eb0 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -228,6 +228,329 @@ class LogStreamPDO extends LogStream { return SUCCESS; } + + /* + * 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] . "
"; + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrFieldKeys) ) + { + OutputDebugMessage("LogStreamPDO|VerifyFields: Found Field for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG); + continue; + } + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamPDO|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 + */ + public function VerifyIndexes( $arrProperitesIn ) + { + global $dbmapping, $fields; + + // Get List of Indexes as Array + $arrIndexKeys = $this->GetIndexesAsArray(); + $szTableType = $this->_logStreamConfigObj->DBTableType; + + // Loop through all fields to see which one is missing! + foreach ( $arrProperitesIn as $myproperty ) + { +// echo $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "
"; + if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrIndexKeys) ) + { + OutputDebugMessage("LogStreamPDO|VerifyIndexes: Found INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG); + continue; + } + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamPDO|VerifyIndexes: Missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_WARN); + return ERROR_DB_INDEXESMISSING; + } + } + + // Successfull + return SUCCESS; + } + + + /* + * Implementation of VerifyChecksumTrigger: Checks if checksum trigger exists + */ + public function VerifyChecksumTrigger( $myTriggerProperty ) + { + global $dbmapping, $fields; + + // Avoid Check if TRIGGERS are not supported! + if ( $this->_logStreamConfigObj->GetPDOTriggersSupported() == false ) + return SUCCESS; + + // Get List of Triggers as Array + $arrIndexTriggers = $this->GetTriggersAsArray(); + + $szTableType = $this->_logStreamConfigObj->DBTableType; + $szDBName = $this->_logStreamConfigObj->DBName; + $szTableName = $this->_logStreamConfigObj->DBTableName; + $szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty]; + + // Create Triggername + $szTriggerName = $szDBName . "_" . $szTableName . "_" . $szDBTriggerField; + + // Try to find logstream trigger + if ( count($arrIndexTriggers) > 0 ) + { + if ( in_array($szTriggerName, $arrIndexTriggers) ) + return SUCCESS; + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamPDO|VerifyChecksumTrigger: Missing TRIGGER '" . $szTriggerName . "' for Table '" . $szTableName . "'", DEBUG_WARN); + return ERROR_DB_TRIGGERMISSING; + } + } + else + { + // Index is missing for this field! + OutputDebugMessage("LogStreamPDO|VerifyChecksumTrigger: No TRIGGERS found in your database", DEBUG_WARN); + return ERROR_DB_TRIGGERMISSING; + } + } + + + /* + * Implementation of CreateMissingIndexes: Checks if indexes exist for desired fields + */ + public function CreateMissingIndexes( $arrProperitesIn ) + { + global $dbmapping, $fields, $querycount; + + // Get List of Indexes as Array + $arrIndexKeys = $this->GetIndexesAsArray(); + $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], $arrIndexKeys) ) + continue; + else + { +// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + // Update Table schema now! + $szSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD INDEX ( " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " )"; + + // Index is missing for this field! + OutputDebugMessage("LogStreamPDO|CreateMissingIndexes: Createing missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' - " . $szSql, DEBUG_INFO); + + // Add missing INDEX now! + $myQuery = $this->_dbhandle->query($szSql); + if (!$myQuery) + { + // Return failure! + $this->PrintDebugError("Dynamically Adding INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' failed with Statement: '" . $szSql . "'"); + return ERROR_DB_INDEXFAILED; + } + else // Free query now + $myQuery->closeCursor(); + } + } + + // Successfull + return SUCCESS; + } + + + /* + * 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("LogStreamPDO|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; + +// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + // 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; + + // Avoid if TRIGGERS are not supported! + if ( $this->_logStreamConfigObj->GetPDOTriggersSupported() == false ) + return SUCCESS; + + // Get List of Triggers as Array + $szTableName = $this->_logStreamConfigObj->DBTableName; + $szTableType = $this->_logStreamConfigObj->DBTableType; + $szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty]; + $szDBTriggerCheckSumField = $dbmapping[$szTableType]['DBMAPPINGS'][$myCheckSumProperty]; + + // Get SQL Code to create the trigger! + $szSql = $this->GetCreateMissingTriggerSQL( $szDBTriggerField, $szDBTriggerCheckSumField ); + + // Index is missing for this field! + OutputDebugMessage("LogStreamPDO|CreateMissingTrigger: Creating missing TRIGGER for '" . $szTableName . "' - $szDBTriggerCheckSumField = crc32(NEW.$szDBTriggerField)" . $szSql, DEBUG_INFO); + + // Add missing INDEX now! + $myQuery = $this->_dbhandle->query($szSql); + if (!$myQuery) + { + // Return failure! + $this->PrintDebugError("Dynamically Adding TRIGGER for '" . $szTableName . "' failed!

If you want to manually add the TRIGGER, use the following SQL Command:
" . str_replace("\n", "
", $szSql) . "
"); + return ERROR_DB_TRIGGERFAILED; + } + else // Free query now + $myQuery->closeCursor(); + + // Successfull + return SUCCESS; + } + + + /* + * Implementation of ChangeChecksumFieldUnsigned: Changes the Checkusm field to unsigned! + */ + public function ChangeChecksumFieldUnsigned() + { + global $dbmapping, $fields, $querycount; + + // Get variables + $szTableType = $this->_logStreamConfigObj->DBTableType; + +// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + // 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 = $this->_dbhandle->query($szUpdateSql); + 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; + } + else // Free query now + $myQuery->closeCursor(); + + // 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 = $this->_dbhandle->query($szSql); + if ($myQuery) + { + // Get result! + $myRow = $myQuery->fetch(PDO::FETCH_ASSOC); + if (strpos( strtolower($myRow['Type']), "unsigned") === false ) + { + // return error code! + return ERROR_DB_CHECKSUMERROR; + } + + // Free query now + $myQuery->closeCursor(); + + // 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 @@ -1715,77 +2038,212 @@ class LogStreamPDO 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 = $this->_dbhandle->errorInfo(); - // check matching of error msg! - if ( - preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc[2], $errOutArr ) || // MySQL - preg_match("/column \"(.*?)\" does not exist/", $errdesc[2], $errOutArr ) // PostgreSQL -// ERROR: column "checksum" does not exist LINE 1: ... eventsource, eventcategory, eventuser, systemid, checksum, ... ^ - ) + // 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 ) + // check matching of error msg! + if ( + preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc[2], $errOutArr ) || // MySQL + preg_match("/column \"(.*?)\" does not exist/", $errdesc[2], $errOutArr ) // PostgreSQL +// ERROR: column "checksum" does not exist LINE 1: ... eventsource, eventcategory, eventuser, systemid, checksum, ... ^ + ) + $szMissingField = $errOutArr[1]; + else { - if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && $errOutArr[1] == $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] ) - { - $szUpdateSql = ""; - if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) - { - // MYSQL Statements - if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER ) - $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) NOT NULL DEFAULT '0'"; - if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING ) - $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` varchar(60) NULL"; - 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'"; - } - else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) - { - // MYSQL Statements - if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER ) - $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " int NOT NULL DEFAULT '0'"; - if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING ) - $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " varchar(60) NULL"; - if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE ) - $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " timestamp without time zone NULL"; - } + $this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc[2]); + return ERROR_DB_DBFIELDNOTFOUND; + } + } + + // Set Properties to default if NULL + if ( $arrProperties == null ) + $arrProperties = $this->_arrProperties; + + // Get Tabletype + $szTableType = $this->_logStreamConfigObj->DBTableType; - if ( strlen($szUpdateSql) > 0 ) - { - // Update Table schema now! - $myQuery = $this->_dbhandle->query($szUpdateSql); - 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 // Free query now - $myQuery->closeCursor(); - } - else + // 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] ) + { + $szUpdateSql = ""; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + { + // MYSQL Statements + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER ) + $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` int(11) NOT NULL DEFAULT '0'"; + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING ) + $szUpdateSql = "ALTER TABLE `" . $this->_logStreamConfigObj->DBTableName . "` ADD `" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "` varchar(60) NULL"; + 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'"; + } + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + { + // MYSQL Statements + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER ) + $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " int NOT NULL DEFAULT '0'"; + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING ) + $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " varchar(60) NULL"; + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE ) + $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " timestamp without time zone NULL"; + } + + if ( strlen($szUpdateSql) > 0 ) + { + // Update Table schema now! + $myQuery = $this->_dbhandle->query($szUpdateSql); + 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!'"); + $this->PrintDebugError("ER_BAD_FIELD_ERROR - Dynamically Adding field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' with Statement failed: '" . $szUpdateSql . "'"); return ERROR_DB_DBFIELDNOTFOUND; } + else // Free query now + $myQuery->closeCursor(); + } + 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_DBFIELDNOTFOUND; } } + } - // Reached this point means success! - return SUCCESS; + // Reached this point means success! + return SUCCESS; + } + + + /* + * Helper function to return a list of Indexes for the logstream table + */ + private function GetIndexesAsArray() + { + global $querycount; + + // Verify database connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; + + // Init Array + $arrIndexKeys = array(); + +// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + + // Create SQL and Get INDEXES for table! + $szSql = "SHOW INDEX FROM " . $this->_logStreamConfigObj->DBTableName; + $myQuery = $this->_dbhandle->query($szSql); + if ($myQuery) + { + // Loop through results + while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) ) + { + // Add to index keys + $arrIndexKeys[] = strtolower($myRow['Key_name']); + } + + // Free query now + $myQuery->closeCursor(); + + // Increment for the Footer Stats + $querycount++; + } + + // return Array + return $arrIndexKeys; + } + + + /* + * Helper function to return a list of Fields from the logstream table + */ + private function GetFieldsAsArray() + { + global $querycount; + + // Verify database connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; + + // Init Array + $arrFieldKeys = array(); + +// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + // Create SQL and Get FIELDS for table! + $szSql = "SHOW FIELDS FROM " . $this->_logStreamConfigObj->DBTableName; + $myQuery = $this->_dbhandle->query($szSql); + if ($myQuery) + { + // Loop through results + while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) ) + { + // Add to index keys + $arrFieldKeys[] = strtolower($myRow['Field']); + } + + // Free query now + $myQuery->closeCursor(); + + // Increment for the Footer Stats + $querycount++; } else - $this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc[2]); - return ERROR_DB_DBFIELDNOTFOUND; + $this->PrintDebugError("ERROR_DB_QUERYFAILED - GetFieldsAsArray SQL '" . $szSql . "' failed!"); + + + // return Array + return $arrFieldKeys; + } + + + /* + * Helper function to return a list of Indexes for the logstream table + */ + private function GetTriggersAsArray() + { + global $querycount; + + // Verify database connection (This also opens the database!) + $res = $this->Verify(); + if ( $res != SUCCESS ) + return $res; + + // Init Array + $arrIndexTriggers = array(); + +// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + // Create SQL and Get INDEXES for table! + $szSql = "SHOW TRIGGERS"; + $myQuery = $this->_dbhandle->query($szSql); + if ($myQuery) + { + // Loop through results + while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) ) + { + // Add to index keys + $arrIndexTriggers[] = strtolower($myRow['Trigger']); + } + + // Free query now + $myQuery->closeCursor(); + + // Increment for the Footer Stats + $querycount++; + } + + // return Array + return $arrIndexTriggers; } diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index a2eb8fd..c886fe9 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -476,6 +476,8 @@ $content['LN_REPORTS_ADD_MISSINGFIELDS'] = "The datasource '%1' does not contain $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_RECHECKLOGSTREAMSOURCE'] = "Do you want to check the current logstream source again?"; $content['LN_REPORTS_'] = ""; + ?> \ No newline at end of file diff --git a/src/templates/admin/admin_reports.html b/src/templates/admin/admin_reports.html index e8d2a0b..d9302f1 100644 --- a/src/templates/admin/admin_reports.html +++ b/src/templates/admin/admin_reports.html @@ -276,6 +276,9 @@
{MSG_WARNING_TITLE}

{MSG_WARNING_DETAILS}

+ {LN_REPORTS_RECHECKLOGSTREAMSOURCE} +
+
From 4e133d3a7042536bd3902985021fdf0c55ac2267 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 4 Nov 2011 15:42:50 +0100 Subject: [PATCH 16/23] Fixed report support for POSTGRESQL in PDO logstream class --- src/classes/logstreamdb.class.php | 12 +- src/classes/logstreampdo.class.php | 124 ++++++++++++++---- .../report.eventlog.eventsummary.class.php | 14 +- ...report.eventlog.eventsummary.template.html | 16 +-- .../report.eventlog.eventsummary.template.pdf | 16 +-- .../report.syslog.syslogsummary.class.php | 30 ++--- .../report.syslog.syslogsummary.template.html | 16 +-- .../report.syslog.syslogsummary.template.pdf | 16 +-- src/include/functions_common.php | 8 +- 9 files changed, 164 insertions(+), 88 deletions(-) diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 2e18592..9c37679 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -1019,7 +1019,7 @@ class LogStreamDB extends LogStream { // Set Sorted Field if ( $szConsFieldId == $szSortFieldId ) - $myDBSortedFieldName = "ItemCount"; + $myDBSortedFieldName = "itemcount"; else $myDBSortedFieldName = $szSortFieldId; // --- @@ -1049,7 +1049,7 @@ class LogStreamDB extends LogStream { // Create SQL String now! $szSql = "SELECT " . $myDBQueryFields . - "count(" . $myDBConsFieldName . ") as ItemCount " . + "count(" . $myDBConsFieldName . ") as itemcount " . " FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause . " GROUP BY " . $myDBGroupByFieldName . @@ -1153,12 +1153,12 @@ class LogStreamDB extends LogStream { // Add Min and Max fields for DATE if desired if ( $bIncludeMinMaxDateFields ) { - $myDBQueryFields .= "Min(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as FirstOccurrence_Date, "; - $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as LastOccurrence_Date, "; + $myDBQueryFields .= "Min(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as firstoccurrence_date, "; + $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as lastoccurrence_date, "; } if ( $szConsFieldId == $szSortFieldId ) - $myDBSortedFieldName = "ItemCount"; + $myDBSortedFieldName = "itemcount"; else $myDBSortedFieldName = $szSortFieldId; // --- @@ -1188,7 +1188,7 @@ class LogStreamDB extends LogStream { // Create SQL String now! $szSql = "SELECT " . $myDBQueryFields . - "count(" . $myDBConsFieldName . ") as ItemCount " . + "count(" . $myDBConsFieldName . ") as itemcount " . " FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause . " GROUP BY " . $myDBGroupByFieldName . diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 2752eb0..29d3874 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -137,8 +137,7 @@ class LogStreamPDO extends LogStream { // trigger closing database query! $this->DestroyMainSQLQuery(); -// TODO CLOSE DB CONN?! - + // TODO CLOSE DB CONN?! return true; } @@ -240,6 +239,10 @@ class LogStreamPDO extends LogStream { $arrFieldKeys = $this->GetFieldsAsArray(); $szTableType = $this->_logStreamConfigObj->DBTableType; + // FIELD Listing failed! Nothing we can do in this case! + if ( $arrFieldKeys == null ) + return SUCCESS; + // Loop through all fields to see which one is missing! foreach ( $arrProperitesIn as $myproperty ) { @@ -273,10 +276,19 @@ class LogStreamPDO extends LogStream { $arrIndexKeys = $this->GetIndexesAsArray(); $szTableType = $this->_logStreamConfigObj->DBTableType; + // INDEX Listing failed! Nothing we can do in this case! + if ( !isset($arrIndexKeys) )// == null ) + return SUCCESS; + // Loop through all fields to see which one is missing! foreach ( $arrProperitesIn as $myproperty ) { -// echo $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "
"; + if ( count($arrIndexKeys) <= 0 ) + { + // NO INDEXES at all! + OutputDebugMessage("LogStreamPDO|VerifyIndexes: NO INDEXES found !", DEBUG_WARN); + return ERROR_DB_INDEXESMISSING; + } if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty]) && in_array($dbmapping[$szTableType]['DBMAPPINGS'][$myproperty], $arrIndexKeys) ) { OutputDebugMessage("LogStreamPDO|VerifyIndexes: Found INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "'", DEBUG_ULTRADEBUG); @@ -309,6 +321,10 @@ class LogStreamPDO extends LogStream { // Get List of Triggers as Array $arrIndexTriggers = $this->GetTriggersAsArray(); + // TRIGGER Listing failed! Nothing we can do in this case! + if ( $arrIndexTriggers == null ) + return SUCCESS; + $szTableType = $this->_logStreamConfigObj->DBTableType; $szDBName = $this->_logStreamConfigObj->DBName; $szTableName = $this->_logStreamConfigObj->DBTableName; @@ -356,9 +372,15 @@ class LogStreamPDO extends LogStream { continue; else { -// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) // Update Table schema now! - $szSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD INDEX ( " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " )"; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + $szSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD INDEX ( " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " )"; + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $szSql = "CREATE INDEX " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "_idx ON " . $this->_logStreamConfigObj->DBTableName . " (" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . ");"; + else + // Not supported in this case! + return ERROR_DB_INDEXFAILED; + // Index is missing for this field! OutputDebugMessage("LogStreamPDO|CreateMissingIndexes: Createing missing INDEX for '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' - " . $szSql, DEBUG_INFO); @@ -1024,9 +1046,25 @@ class LogStreamPDO extends LogStream { $szTableType = $this->_logStreamConfigObj->DBTableType; // 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"; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + { + $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 OR " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = 0"; + } + elseif ($this->_logStreamConfigObj->DBType == DB_PGSQL ) + { + $szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName . + " SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = hashtext(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_MESSAGE] . ") " . + " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL OR " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = 0"; + } +//MSSQL: binary_checksum + else + { + // Failed | Checksum function not supported! + $this->PrintDebugError("UpdateAllMessageChecksum failed, PDO LogStream does not support CRC32 Checksums in SQL Statements!"); + return ERROR; + } // Output Debug Informations OutputDebugMessage("LogStreamPDO|UpdateAllMessageChecksum: Running Created SQL Query:
" . $szSql, DEBUG_ULTRADEBUG); @@ -1129,7 +1167,7 @@ class LogStreamPDO extends LogStream { // Set Sorted Field if ( $szConsFieldId == $szSortFieldId ) - $myDBSortedFieldName = "ItemCount"; + $myDBSortedFieldName = "itemcount"; else $myDBSortedFieldName = $szSortFieldId; // --- @@ -1175,7 +1213,7 @@ class LogStreamPDO extends LogStream { // Create SQL String now! $szSql = "SELECT " . $myDBQueryFields . - "count(" . $myDBConsFieldName . ") as ItemCount " . + "count(" . $myDBConsFieldName . ") as itemcount " . " FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause . " GROUP BY " . $myDBGroupByFieldName . @@ -1269,12 +1307,24 @@ class LogStreamPDO extends LogStream { foreach ( $aIncludeCustomFields as $myFieldName ) { if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName]) ) - $myDBQueryFields .= $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + { + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ") AS " . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + else + // Default for other PDO Engines + $myDBQueryFields .= $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + } } // Append Sortingfield if ( !in_array($szConsFieldId, $aIncludeCustomFields) ) - $myDBQueryFields .= $myDBConsFieldName . ", "; + { + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $myDBQueryFields .= "Max(" . $myDBConsFieldName . ") AS " . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + else + // Default for other PDO Engines + $myDBQueryFields .= $myDBConsFieldName . ", "; + } } else if ( $bIncludeLogStreamFields ) { @@ -1282,21 +1332,33 @@ class LogStreamPDO extends LogStream { foreach ( $this->_arrProperties as $myFieldName ) { if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName]) ) - $myDBQueryFields .= $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + { + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ") AS " . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + else + // Default for other PDO Engines + $myDBQueryFields .= $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; + } } } else // Only Include ConsolidateField - $myDBQueryFields = $myDBConsFieldName . ", "; + { + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $myDBQueryFields = "Max(" . $myDBConsFieldName . ") as " . $myDBConsFieldName. ", "; + else + // Default for other PDO Engines + $myDBQueryFields = $myDBConsFieldName . ", "; + } // Add Min and Max fields for DATE if desired if ( $bIncludeMinMaxDateFields ) { - $myDBQueryFields .= "Min(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as FirstOccurrence_Date, "; - $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as LastOccurrence_Date, "; + $myDBQueryFields .= "Min(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as firstoccurrence_date, "; + $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_DATE] . ") as lastoccurrence_date, "; } if ( $szConsFieldId == $szSortFieldId ) - $myDBSortedFieldName = "ItemCount"; + $myDBSortedFieldName = "itemcount"; else $myDBSortedFieldName = $szSortFieldId; // --- @@ -1334,7 +1396,7 @@ class LogStreamPDO extends LogStream { // Create SQL String now! $szSql = "SELECT " . $myDBQueryFields . - "count(" . $myDBConsFieldName . ") as ItemCount " . + "count(" . $myDBConsFieldName . ") as itemcount " . " FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause . " GROUP BY " . $myDBGroupByFieldName . @@ -2138,10 +2200,15 @@ class LogStreamPDO extends LogStream { // Init Array $arrIndexKeys = array(); -// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) - // Create SQL and Get INDEXES for table! - $szSql = "SHOW INDEX FROM " . $this->_logStreamConfigObj->DBTableName; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + $szSql = "SHOW INDEX FROM " . $this->_logStreamConfigObj->DBTableName; + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $szSql = "SELECT c.relname AS \"Key_name\" FROM pg_catalog.pg_class c JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid JOIN pg_catalog.pg_class t ON i.indrelid = t.oid WHERE c.relkind = 'i' AND t.relname = 'systemevents' AND c.relname LIKE '%idx%'"; + else + // Not supported in this case! + return null; + $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { @@ -2149,7 +2216,10 @@ class LogStreamPDO extends LogStream { while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) ) { // Add to index keys - $arrIndexKeys[] = strtolower($myRow['Key_name']); + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $arrIndexKeys[] = str_replace( "_idx", "", strtolower($myRow['Key_name']) ); + else + $arrIndexKeys[] = strtolower($myRow['Key_name']); } // Free query now @@ -2179,9 +2249,15 @@ class LogStreamPDO extends LogStream { // Init Array $arrFieldKeys = array(); -// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) // Create SQL and Get FIELDS for table! - $szSql = "SHOW FIELDS FROM " . $this->_logStreamConfigObj->DBTableName; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + $szSql = "SHOW FIELDS FROM " . $this->_logStreamConfigObj->DBTableName; + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $szSql = "SELECT column_name as \"Field\" FROM information_schema.COLUMNS WHERE table_name = '" . $this->_logStreamConfigObj->DBTableName . "'"; + else + // Not supported in this case! + return null; + $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { diff --git a/src/classes/reports/report.eventlog.eventsummary.class.php b/src/classes/reports/report.eventlog.eventsummary.class.php index 062e9f7..87fe38e 100644 --- a/src/classes/reports/report.eventlog.eventsummary.class.php +++ b/src/classes/reports/report.eventlog.eventsummary.class.php @@ -160,13 +160,13 @@ class Report_eventsummary extends Report { $tmpReportData['DisplayName'] = GetSeverityDisplayName( $tmpReportData[SYSLOG_SEVERITY] ); $tmpReportData['bgcolor'] = $severity_colors[ $tmpReportData[SYSLOG_SEVERITY] ]; - $iTotalEvents += $tmpReportData['ItemCount']; + $iTotalEvents += $tmpReportData['itemcount']; } // Prepent Item with totalevents count $totalItem['DisplayName'] = "Total Events"; $totalItem['bgcolor'] = "#999999"; - $totalItem['ItemCount'] = $iTotalEvents; + $totalItem['itemcount'] = $iTotalEvents; // Prepent to array array_unshift( $content["report_summary"], $totalItem ); @@ -422,7 +422,7 @@ class Report_eventsummary extends Report { if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]) ) { // Increment counter and set First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['ItemCount']++; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['itemcount']++; // Set FirstEvent date if necessary! if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'][EVTIME_TIMESTAMP] ) @@ -441,7 +441,7 @@ class Report_eventsummary extends Report { $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE]; // Set Counter and First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['ItemCount'] = 1; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['itemcount'] = 1; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_Date'] = $logArray[SYSLOG_DATE]; } @@ -481,7 +481,7 @@ class Report_eventsummary extends Report { $lastEntry[SYSLOG_EVENT_ID] = "-"; $lastEntry[SYSLOG_EVENT_SOURCE] = $content['LN_GEN_ALL_OTHER_EVENTS']; $lastEntry[SYSLOG_MESSAGE] = $content['LN_GEN_ALL_OTHER_EVENTS']; - $lastEntry['ItemCount'] = $iDropCount; + $lastEntry['itemcount'] = $iDropCount; $lastEntry['FirstEvent_Date'] = "-"; $lastEntry['LastEvent_Date'] = "-"; @@ -496,8 +496,8 @@ class Report_eventsummary extends Report { // PostProcess Events! foreach( $tmpConsolidatedComputer["cons_events"] as &$tmpMyEvent ) { - $tmpMyEvent['FirstEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['FirstOccurrence_Date'] ); - $tmpMyEvent['LastEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['LastOccurrence_Date'] ); + $tmpMyEvent['FirstEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['firstoccurrence_date'] ); + $tmpMyEvent['LastEvent_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['lastoccurrence_date'] ); $tmpMyEvent['syslogseverity_text'] = $content['filter_severity_list'][ $tmpMyEvent['syslogseverity'] ]["DisplayName"]; $tmpMyEvent['syslogseverity_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogseverity']); } diff --git a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html index d31ca2d..7efd33a 100644 --- a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html +++ b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.html @@ -56,7 +56,7 @@ {DisplayName} - {ItemCount} + {itemcount} @@ -68,7 +68,7 @@ - {FROMHOST}({ItemCount}), + {FROMHOST}({itemcount}), @@ -105,12 +105,12 @@ {ZAEHLER} - - {ItemCount} - - - {ItemCount} - + + {itemcount} + + + {itemcount} + {FirstEvent_Date_Formatted} {LastEvent_Date_Formatted} {sourceproc} diff --git a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf index 6392adb..61bc6ef 100644 --- a/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf +++ b/src/classes/reports/report.eventlog.eventsummary/report.eventlog.eventsummary.template.pdf @@ -38,7 +38,7 @@ {DisplayName} - {ItemCount} + {itemcount} @@ -52,7 +52,7 @@ - {FROMHOST}({ItemCount}), + {FROMHOST}({itemcount}), @@ -78,12 +78,12 @@ {ZAEHLER} - - {ItemCount} - - - {ItemCount} - + + {itemcount} + + + {itemcount} + {FirstEvent_Date_Formatted} {LastEvent_Date_Formatted} {sourceproc} diff --git a/src/classes/reports/report.syslog.syslogsummary.class.php b/src/classes/reports/report.syslog.syslogsummary.class.php index 31bbcf7..ac70ede 100644 --- a/src/classes/reports/report.syslog.syslogsummary.class.php +++ b/src/classes/reports/report.syslog.syslogsummary.class.php @@ -157,13 +157,13 @@ class Report_syslogsummary extends Report { $tmpReportData['DisplayName'] = $this->GetSeverityDisplayName( $tmpReportData[SYSLOG_SEVERITY] ); $tmpReportData['bgcolor'] = $this->GetSeverityBGColor( $tmpReportData[SYSLOG_SEVERITY] ); // $severity_colors[ $tmpReportData[SYSLOG_SEVERITY] ]; - $iTotalEvents += $tmpReportData['ItemCount']; + $iTotalEvents += $tmpReportData['itemcount']; } // Prepent Item with totalevents count $totalItem['DisplayName'] = "Total Events"; $totalItem['bgcolor'] = "#999999"; - $totalItem['ItemCount'] = $iTotalEvents; + $totalItem['itemcount'] = $iTotalEvents; // Prepent to array array_unshift( $content["report_summary"], $totalItem ); @@ -423,15 +423,15 @@ class Report_syslogsummary extends Report { if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]) ) { // Increment counter and set First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount']++; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['itemcount']++; // Set FirstEvent date if necessary! - if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'][EVTIME_TIMESTAMP] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['firstoccurrence_date'][EVTIME_TIMESTAMP] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['firstoccurrence_date'] = $logArray[SYSLOG_DATE]; // Set LastEvent date if necessary! - if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'][EVTIME_TIMESTAMP] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['lastoccurrence_date'][EVTIME_TIMESTAMP] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['lastoccurrence_date'] = $logArray[SYSLOG_DATE]; } else { @@ -448,9 +448,9 @@ class Report_syslogsummary extends Report { $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE]; // Set Counter and First/Last Event date - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['ItemCount'] = 1; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['FirstOccurrence_Date'] = $logArray[SYSLOG_DATE]; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['LastOccurrence_Date'] = $logArray[SYSLOG_DATE]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['itemcount'] = 1; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['firstoccurrence_date'] = $logArray[SYSLOG_DATE]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_msgs'][ $strChecksum ]['lastoccurrence_date'] = $logArray[SYSLOG_DATE]; } } @@ -490,9 +490,9 @@ class Report_syslogsummary extends Report { $lastEntry[SYSLOG_FACILITY] = SYSLOG_LOCAL0; $lastEntry[SYSLOG_SYSLOGTAG] = $content['LN_GEN_ALL_OTHER_EVENTS']; $lastEntry[SYSLOG_MESSAGE] = $content['LN_GEN_ALL_OTHER_EVENTS']; - $lastEntry['ItemCount'] = $iDropCount; - $lastEntry['FirstOccurrence_Date'] = "-"; - $lastEntry['LastOccurrence_Date'] = "-"; + $lastEntry['itemcount'] = $iDropCount; + $lastEntry['firstoccurrence_date'] = "-"; + $lastEntry['lastoccurrence_date'] = "-"; $tmpConsolidatedComputer['cons_msgs'][] = $lastEntry; } @@ -505,8 +505,8 @@ class Report_syslogsummary extends Report { // PostProcess Events! foreach( $tmpConsolidatedComputer["cons_msgs"] as &$tmpMyEvent ) { - $tmpMyEvent['FirstOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['FirstOccurrence_Date'] ); - $tmpMyEvent['LastOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['LastOccurrence_Date'] ); + $tmpMyEvent['FirstOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['firstoccurrence_date'] ); + $tmpMyEvent['LastOccurrence_Date_Formatted'] = GetFormatedDate( $tmpMyEvent['lastoccurrence_date'] ); $tmpMyEvent['syslogseverity_text'] = $this->GetSeverityDisplayName($tmpMyEvent['syslogseverity']); //$content['filter_severity_list'][ $tmpMyEvent['syslogseverity'] ]["DisplayName"]; $tmpMyEvent['syslogfacility_text'] = $this->GetFacilityDisplayName($tmpMyEvent['syslogfacility']); //$content['filter_facility_list'][ $tmpMyEvent['syslogfacility'] ]["DisplayName"]; $tmpMyEvent['syslogseverity_bgcolor'] = $this->GetSeverityBGColor($tmpMyEvent['syslogseverity']); diff --git a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html index 4001010..5f7d9b6 100644 --- a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html +++ b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.html @@ -57,7 +57,7 @@ {DisplayName} - {ItemCount} + {itemcount} @@ -69,7 +69,7 @@ - {FROMHOST}({ItemCount}), + {FROMHOST}({itemcount}), @@ -106,12 +106,12 @@ {ZAEHLER} - - {ItemCount} - - - {ItemCount} - + + {itemcount} + + + {itemcount} + {FirstOccurrence_Date_Formatted} {LastOccurrence_Date_Formatted} {syslogseverity_text} diff --git a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf index 021a379..ca1cc94 100644 --- a/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf +++ b/src/classes/reports/report.syslog.syslogsummary/report.syslog.syslogsummary.template.pdf @@ -38,7 +38,7 @@ {DisplayName} - {ItemCount} + {itemcount} @@ -52,7 +52,7 @@ - {FROMHOST}({ItemCount}), + {FROMHOST}({itemcount}), @@ -78,12 +78,12 @@ {ZAEHLER} - - {ItemCount} - - - {ItemCount} - + + {itemcount} + + + {itemcount} + {FirstOccurrence_Date_Formatted} {LastOccurrence_Date_Formatted} {syslogseverity_text} diff --git a/src/include/functions_common.php b/src/include/functions_common.php index cbf4fb4..59045eb 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -1935,11 +1935,11 @@ function GetErrorMessage($errorCode) function MultiSortArrayByItemCountDesc( $arrayFirst, $arraySecond ) { // Do not sort in this case - if ($arrayFirst['ItemCount'] == $arraySecond['ItemCount']) + if ($arrayFirst['itemcount'] == $arraySecond['itemcount']) return 0; // Move up or down - return ($arrayFirst['ItemCount'] < $arraySecond['ItemCount']) ? 1 : -1; + return ($arrayFirst['itemcount'] < $arraySecond['itemcount']) ? 1 : -1; } /** @@ -1948,11 +1948,11 @@ function MultiSortArrayByItemCountDesc( $arrayFirst, $arraySecond ) function MultiSortArrayByItemCountAsc( $arrayFirst, $arraySecond ) { // Do not sort in this case - if ($arrayFirst['ItemCount'] == $arraySecond['ItemCount']) + if ($arrayFirst['itemcount'] == $arraySecond['itemcount']) return 0; // Move up or down - return ($arrayFirst['ItemCount'] < $arraySecond['ItemCount']) ? -1 : 1; + return ($arrayFirst['itemcount'] < $arraySecond['itemcount']) ? -1 : 1; } // --- From 739598874e355dbb00cbb12d6a25d6067cfadbcd Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 4 Nov 2011 16:28:24 +0100 Subject: [PATCH 17/23] Added Trigger Support for PostGRESQL PDO Driver in PDO LogStream Class --- src/classes/logstreampdo.class.php | 38 +++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 29d3874..ddf0cfb 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -331,13 +331,16 @@ class LogStreamPDO extends LogStream { $szDBTriggerField = $dbmapping[$szTableType]['DBMAPPINGS'][$myTriggerProperty]; // Create Triggername - $szTriggerName = $szDBName . "_" . $szTableName . "_" . $szDBTriggerField; + $szTriggerName = strtolower($szDBName . "_" . $szTableName . "_" . $szDBTriggerField); // Try to find logstream trigger if ( count($arrIndexTriggers) > 0 ) { if ( in_array($szTriggerName, $arrIndexTriggers) ) + { + OutputDebugMessage("LogStreamPDO|VerifyChecksumTrigger: Found TRIGGER '" . $szTriggerName. "' for table '" . $szTableName . "'", DEBUG_ULTRADEBUG); return SUCCESS; + } else { // Index is missing for this field! @@ -452,16 +455,33 @@ class LogStreamPDO extends LogStream { $szTableName = $this->_logStreamConfigObj->DBTableName; // Create Triggername - $szTriggerName = $szDBName . "_" . $szTableName . "_" . $myDBTriggerField; + $szTriggerName = strtolower($szDBName . "_" . $szTableName . "_" . $myDBTriggerField); -// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) // Create TRIGGER SQL! - $szSql = "CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT ON `" . $szTableName . "` + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + $szSql ="CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT ON `" . $szTableName . "` FOR EACH ROW BEGIN SET NEW." . $myDBTriggerCheckSumField . " = crc32(NEW." . $myDBTriggerField . "); END ;"; + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + // Experimental Trigger Support for POSTGRESQL + $szSql =" + CREATE LANGUAGE plpgsql ; + CREATE FUNCTION " . $szTriggerName . "() RETURNS trigger AS $" . $szTriggerName . "$ + BEGIN + NEW." . $myDBTriggerCheckSumField . " := hashtext(NEW." . $myDBTriggerField . "); + RETURN NEW; + END; + $" . $szTriggerName . "$ LANGUAGE plpgsql; + + CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT OR UPDATE ON \"" . $szTableName . "\" + FOR EACH ROW EXECUTE PROCEDURE " . $szTriggerName . "(); + "; + else + // NOT SUPPORTED + return null; return $szSql; } @@ -2298,9 +2318,15 @@ class LogStreamPDO extends LogStream { // Init Array $arrIndexTriggers = array(); -// TODO if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) // Create SQL and Get INDEXES for table! - $szSql = "SHOW TRIGGERS"; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + $szSql = "SHOW TRIGGERS"; + else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $szSql = "select tgname as \"Trigger\" from pg_trigger;"; + else + // Not supported in this case! + return null; + $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { From 3d8f5074c6c5b37a494e3a82701aa11f101d80bb Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 9 Nov 2011 10:16:08 +0100 Subject: [PATCH 18/23] Added support to automatically add missing fields for MSSQL Driver in PDO LogStream class --- src/classes/logstreampdo.class.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 4d6818f..c1454ab 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -2166,18 +2166,21 @@ class LogStreamPDO extends LogStream { { // check matching of error msg! if ( - preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc[2], $errOutArr ) || // MySQL - preg_match("/column \"(.*?)\" does not exist/", $errdesc[2], $errOutArr ) // PostgreSQL + preg_match("/Unknown column '(.*?)' in '(.*?)'$/", $errdesc[2], $errOutArr ) || // MySQL + preg_match("/column \"(.*?)\" does not exist/", $errdesc[2], $errOutArr ) || // PostgreSQL + preg_match("/Invalid column name '(.*?)'/", $errdesc[2], $errOutArr ) // MSSQL // ERROR: column "checksum" does not exist LINE 1: ... eventsource, eventcategory, eventuser, systemid, checksum, ... ^ ) + { $szMissingField = $errOutArr[1]; + } else { $this->PrintDebugError("ER_BAD_FIELD_ERROR - SQL Statement: ". $errdesc[2]); return ERROR_DB_DBFIELDNOTFOUND; } } - + // Set Properties to default if NULL if ( $arrProperties == null ) $arrProperties = $this->_arrProperties; @@ -2211,7 +2214,18 @@ class LogStreamPDO extends LogStream { if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_DATE ) $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " timestamp without time zone NULL"; } - + else if ( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + { + // MYSQL Statements + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_NUMBER ) + $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " INT NOT NULL DEFAULT '0'"; + if ( $fields[$myproperty]['FieldType'] == FILTER_TYPE_STRING ) + $szUpdateSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " VARCHAR(60) NULL"; + 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'"; + } + + // Run SQL Command to add the missing field! if ( strlen($szUpdateSql) > 0 ) { // Update Table schema now! @@ -2228,7 +2242,7 @@ class LogStreamPDO extends LogStream { 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!'"); + $this->PrintDebugError("ER_BAD_FIELD_ERROR - Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' is missing and failed to be added automatically! The fields has to be added manually to the database layout!'"); return ERROR_DB_DBFIELDNOTFOUND; } } From 78407d984420a87edcad16702b7a6e14cd9e3402 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 9 Nov 2011 11:35:29 +0100 Subject: [PATCH 19/23] Added support to create INDEXES, FIELDS and TRIGGERS for MSSQL in PDO Logstream Also fixed support for MSSQL for reports. --- src/classes/logstreampdo.class.php | 92 +++++++++++++++++++---- src/include/functions_frontendhelpers.php | 35 +++++---- 2 files changed, 100 insertions(+), 27 deletions(-) diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index c1454ab..d9c1973 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -322,7 +322,8 @@ class LogStreamPDO extends LogStream { $arrIndexTriggers = $this->GetTriggersAsArray(); // TRIGGER Listing failed! Nothing we can do in this case! - if ( $arrIndexTriggers == null ) + if ( !isset($arrIndexTriggers) )// == null ) +// if ( $arrIndexTriggers == null ) return SUCCESS; $szTableType = $this->_logStreamConfigObj->DBTableType; @@ -380,6 +381,8 @@ class LogStreamPDO extends LogStream { $szSql = "ALTER TABLE " . $this->_logStreamConfigObj->DBTableName . " ADD INDEX ( " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . " )"; else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) $szSql = "CREATE INDEX " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "_idx ON " . $this->_logStreamConfigObj->DBTableName . " (" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . ");"; + else if ( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + $szSql = "CREATE INDEX " . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "_idx ON " . $this->_logStreamConfigObj->DBTableName . " (" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . ");"; else // Not supported in this case! return ERROR_DB_INDEXFAILED; @@ -479,6 +482,22 @@ class LogStreamPDO extends LogStream { CREATE TRIGGER " . $szTriggerName . " BEFORE INSERT OR UPDATE ON \"" . $szTableName . "\" FOR EACH ROW EXECUTE PROCEDURE " . $szTriggerName . "(); "; + else if ( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + { + // Trigger code for MSSQL! + $szSql ="CREATE TRIGGER " . $szTriggerName . " ON " . $szTableName . " AFTER INSERT AS + BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for trigger here + UPDATE " . $szTableName . " + SET " . $myDBTriggerCheckSumField . " = checksum(I." . $myDBTriggerField . ") + FROM systemevents JOIN inserted I on " . $szTableName . "." . $dbmapping[$szTableType]['DBMAPPINGS']['SYSLOG_UID'] . " = I." . $dbmapping[$szTableType]['DBMAPPINGS']['SYSLOG_UID'] . " + END + "; + } else // NOT SUPPORTED return null; @@ -569,7 +588,13 @@ class LogStreamPDO extends LogStream { $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] . "'"; + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) + $szSql = "SHOW COLUMNS FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE Field = '" . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . "'"; + else + // NOT SUPPORTED or NEEDED + return SUCCESS; + + // Run Query to check the Checksum field! $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { @@ -1100,7 +1125,12 @@ class LogStreamPDO extends LogStream { " SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = hashtext(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_MESSAGE] . ") " . " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL OR " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = 0"; } -//MSSQL: binary_checksum + elseif ($this->_logStreamConfigObj->DBType == DB_MSSQL ) + { + $szSql = "UPDATE " . $this->_logStreamConfigObj->DBTableName . + " SET " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = checksum(" . $dbmapping[$szTableType]['DBMAPPINGS'][SYSLOG_MESSAGE] . ") " . + " WHERE " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " IS NULL OR " . $dbmapping[$szTableType]['DBMAPPINGS'][MISC_CHECKSUM] . " = 0"; + } else { // Failed | Checksum function not supported! @@ -1350,7 +1380,8 @@ class LogStreamPDO extends LogStream { { if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName]) ) { - if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL || + $this->_logStreamConfigObj->DBType == DB_MSSQL ) $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ") AS " . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; else // Default for other PDO Engines @@ -1361,7 +1392,8 @@ class LogStreamPDO extends LogStream { // Append Sortingfield if ( !in_array($szConsFieldId, $aIncludeCustomFields) ) { - if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL || + $this->_logStreamConfigObj->DBType == DB_MSSQL ) $myDBQueryFields .= "Max(" . $myDBConsFieldName . ") AS " . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; else // Default for other PDO Engines @@ -1375,7 +1407,8 @@ class LogStreamPDO extends LogStream { { if ( isset($dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName]) ) { - if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL || + $this->_logStreamConfigObj->DBType == DB_MSSQL ) $myDBQueryFields .= "Max(" . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ") AS " . $dbmapping[$szTableType]['DBMAPPINGS'][$myFieldName] . ", "; else // Default for other PDO Engines @@ -1385,7 +1418,8 @@ class LogStreamPDO extends LogStream { } else // Only Include ConsolidateField { - if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL || + $this->_logStreamConfigObj->DBType == DB_MSSQL ) $myDBQueryFields = "Max(" . $myDBConsFieldName . ") as " . $myDBConsFieldName. ", "; else // Default for other PDO Engines @@ -1418,6 +1452,9 @@ class LogStreamPDO extends LogStream { else if($this->_logStreamConfigObj->DBType == DB_MSSQL ) { // TODO FIND A WAY FOR MSSQL! + // Helper variable for the select statement + $mySelectFieldName = $myDBGroupByFieldName . "Grouped"; + $myDBQueryFieldName = "DATE( " . $myDBConsFieldName . ") AS " . $myDBGroupByFieldName ; } } @@ -1427,23 +1464,37 @@ class LogStreamPDO extends LogStream { // Append LIMIT in this case! if ( $this->_logStreamConfigObj->DBType == DB_MYSQL || $this->_logStreamConfigObj->DBType == DB_PGSQL ) - $szLimitSql = " LIMIT " . $nRecordLimit; + { + $szLimitSqlBefore = ""; + $szLimitSqlAfter = " LIMIT " . $nRecordLimit; + } + else if( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + { + $szLimitSqlBefore = " TOP(" . $nRecordLimit . ") "; + $szLimitSqlAfter = ""; + } else - $szLimitSql = ""; - // TODO FIND A WAY FOR MSSQL! + { + $szLimitSqlBefore = ""; + $szLimitSqlAfter = ""; + } } else - $szLimitSql = ""; + { + $szLimitSqlBefore = ""; + $szLimitSqlAfter = ""; + } // Create SQL String now! $szSql = "SELECT " . + $szLimitSqlBefore . $myDBQueryFields . "count(" . $myDBConsFieldName . ") as itemcount " . " FROM " . $this->_logStreamConfigObj->DBTableName . $this->_SQLwhereClause . " GROUP BY " . $myDBGroupByFieldName . " ORDER BY " . $myDBSortedFieldName . " " . $szSortingOrder . - $szLimitSql ; + $szLimitSqlAfter ; // Output Debug Informations OutputDebugMessage("LogStreamPDO|ConsolidateDataByField: Running Created SQL Query:
" . $szSql, DEBUG_DEBUG); @@ -2243,6 +2294,10 @@ class LogStreamPDO extends LogStream { { // Return failure! $this->PrintDebugError("ER_BAD_FIELD_ERROR - Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' is missing and failed to be added automatically! The fields has to be added manually to the database layout!'"); + + global $extraErrorDescription; + $extraErrorDescription = "Field '" . $dbmapping[$szTableType]['DBMAPPINGS'][$myproperty] . "' was missing and has been automatically added to the database layout."; + return ERROR_DB_DBFIELDNOTFOUND; } } @@ -2273,10 +2328,13 @@ class LogStreamPDO extends LogStream { $szSql = "SHOW INDEX FROM " . $this->_logStreamConfigObj->DBTableName; else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) $szSql = "SELECT c.relname AS \"Key_name\" FROM pg_catalog.pg_class c JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid JOIN pg_catalog.pg_class t ON i.indrelid = t.oid WHERE c.relkind = 'i' AND t.relname = 'systemevents' AND c.relname LIKE '%idx%'"; + else if ( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + $szSql = "SELECT sysindexes.name AS Key_name FROM sysobjects, sysindexes WHERE sysobjects.xtype='U' AND sysindexes.id=object_id(sysobjects.name) and sysobjects.name='" . $this->_logStreamConfigObj->DBTableName . "' ORDER BY sysobjects.name ASC"; else // Not supported in this case! return null; + OutputDebugMessage("LogStreamPDO|GetIndexesAsArray: List Indexes for '" . $this->_logStreamConfigObj->DBTableName . "' - " . $szSql, DEBUG_ULTRADEBUG); $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { @@ -2284,7 +2342,7 @@ class LogStreamPDO extends LogStream { while ( $myRow = $myQuery->fetch(PDO::FETCH_ASSOC) ) { // Add to index keys - if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) + if ( $this->_logStreamConfigObj->DBType == DB_PGSQL || $this->_logStreamConfigObj->DBType == DB_MSSQL ) $arrIndexKeys[] = str_replace( "_idx", "", strtolower($myRow['Key_name']) ); else $arrIndexKeys[] = strtolower($myRow['Key_name']); @@ -2322,10 +2380,13 @@ class LogStreamPDO extends LogStream { $szSql = "SHOW FIELDS FROM " . $this->_logStreamConfigObj->DBTableName; else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) $szSql = "SELECT column_name as \"Field\" FROM information_schema.COLUMNS WHERE table_name = '" . $this->_logStreamConfigObj->DBTableName . "'"; + else if ( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + $szSql = "SELECT syscolumns.name AS Field FROM sysobjects JOIN syscolumns ON sysobjects.id = syscolumns.id WHERE sysobjects.xtype='U' AND sysobjects.name='" . $this->_logStreamConfigObj->DBTableName . "'"; else // Not supported in this case! return null; + OutputDebugMessage("LogStreamPDO|GetFieldsAsArray: List Columns for '" . $this->_logStreamConfigObj->DBTableName . "' - " . $szSql, DEBUG_ULTRADEBUG); $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { @@ -2370,11 +2431,14 @@ class LogStreamPDO extends LogStream { if ( $this->_logStreamConfigObj->DBType == DB_MYSQL ) $szSql = "SHOW TRIGGERS"; else if ( $this->_logStreamConfigObj->DBType == DB_PGSQL ) - $szSql = "select tgname as \"Trigger\" from pg_trigger;"; + $szSql = "SELECT tgname as \"Trigger\" from pg_trigger;"; + else if ( $this->_logStreamConfigObj->DBType == DB_MSSQL ) + $szSql = "SELECT B.Name as TableName,A.name AS 'Trigger' FROM sysobjects A,sysobjects B WHERE A.xtype='TR' AND A.parent_obj = B.id"; // AND B.Name='systemevents'"; else // Not supported in this case! return null; + OutputDebugMessage("LogStreamPDO|GetTriggersAsArray: List Triggers for '" . $this->_logStreamConfigObj->DBTableName . "' - " . $szSql, DEBUG_ULTRADEBUG); $myQuery = $this->_dbhandle->query($szSql); if ($myQuery) { diff --git a/src/include/functions_frontendhelpers.php b/src/include/functions_frontendhelpers.php index 1be9a2e..ce4e5aa 100644 --- a/src/include/functions_frontendhelpers.php +++ b/src/include/functions_frontendhelpers.php @@ -213,23 +213,32 @@ function GetFormatedDate($evttimearray) { global $content; - if ( !is_array($evttimearray) ) - return $evttimearray; - - if ( - GetConfigSetting("ViewUseTodayYesterday", 0, CFGLEVEL_USER) == 1 - && - ( date('m', $evttimearray[EVTIME_TIMESTAMP]) == date('m') && date('Y', $evttimearray[EVTIME_TIMESTAMP]) == date('Y') ) - ) + if ( is_array($evttimearray) ) { - if ( date('d', $evttimearray[EVTIME_TIMESTAMP]) == date('d') ) - return "Today " . date("H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); - else if ( date('d', $evttimearray[EVTIME_TIMESTAMP] + 86400) == date('d') ) - return "Yesterday " . date("H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); + if ( + GetConfigSetting("ViewUseTodayYesterday", 0, CFGLEVEL_USER) == 1 + && + ( date('m', $evttimearray[EVTIME_TIMESTAMP]) == date('m') && date('Y', $evttimearray[EVTIME_TIMESTAMP]) == date('Y') ) + ) + { + if ( date('d', $evttimearray[EVTIME_TIMESTAMP]) == date('d') ) + return "Today " . date("H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); + else if ( date('d', $evttimearray[EVTIME_TIMESTAMP] + 86400) == date('d') ) + return "Yesterday " . date("H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); + } + + // Copy to local variable + $nMyTimeStamp = $evttimearray[EVTIME_TIMESTAMP]; + } + else + { + $nMyTimeStamp = strtotime($evttimearray); + if ( $nMyTimeStamp === FALSE ) // Could not convert into timestamp so return original! + return $evttimearray; } // Reach return normal format! - return $szDateFormatted = date("Y-m-d H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); + return $szDateFormatted = date("Y-m-d H:i:s", $nMyTimeStamp ); } function GetDebugBgColor( $szDebugMode ) From a682dda94f3b246eb44d739e1398620f9e2f8655 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 10 Nov 2011 11:36:05 +0100 Subject: [PATCH 20/23] Changed Report Admin, savedreports can now be changed with returning to the savedreport again. This is useful to check the logstream source after change for optimization. Also added missing language strings to the german language files --- src/admin/reports.php | 134 +++++++++++++++++-------- src/lang/de/admin.php | 37 ++++--- src/lang/de/main.php | 60 +++++++---- src/lang/en/admin.php | 6 +- src/lang/en/main.php | 2 + src/templates/admin/admin_reports.html | 3 + 6 files changed, 162 insertions(+), 80 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index 3cbf8c9..53a6d0d 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -60,10 +60,11 @@ if ( !isset($_SESSION['SESSION_ISREADONLY']) || $_SESSION['SESSION_ISREADONLY'] ( isset($_GET['op']) && ( - $_GET['op'] == "initreport" || - $_GET['op'] == "removereport" || - $_GET['op'] == "addsavedreport" || - $_GET['op'] == "removesavedreport" + strpos($_GET['op'], "initreport") !== false || + strpos($_GET['op'], "removereport") !== false || + strpos($_GET['op'], "editsavedreport") !== false || + strpos($_GET['op'], "addsavedreport") !== false || + strpos($_GET['op'], "removesavedreport") !== false ) ) ) @@ -306,7 +307,7 @@ if ( isset($_GET['op']) ) $content['ERROR_MSG'] = $content['LN_REPORTS_ERROR_INVALIDID']; } } - else if ($_GET['op'] == "addsavedreport") + else if (strpos($_GET['op'], "addsavedreport") !== false ) { if ( isset($_GET['id']) ) { @@ -316,7 +317,9 @@ if ( isset($_GET['op']) ) // Init Form variables $content['ISADDSAVEDREPORT'] = "true"; $content['REPORT_FORMACTION'] = "addsavedreport"; + $content['REPORT_FORMACTIONRETURN'] = "addsavedreport_return"; $content['REPORT_SENDBUTTON'] = $content['LN_REPORTS_ADDSAVEDREPORT']; + $content['REPORT_SENDANDRETURN'] = $content['LN_REPORTS_ADDSAVEDREPORTANDRETURN']; $content['FormUrlAddOP'] = "?op=addsavedreport&id=" . $content['ReportID']; // Check if report exists @@ -392,12 +395,15 @@ if ( isset($_GET['op']) ) $content['ERROR_MSG'] = $content['LN_REPORTS_ERROR_INVALIDID']; } } - else if ($_GET['op'] == "editsavedreport") + else if (strpos($_GET['op'], "editsavedreport") !== false ) { // Set Mode to add $content['ISADDSAVEDREPORT'] = "true"; $content['REPORT_FORMACTION'] = "editsavedreport"; + $content['REPORT_FORMACTIONRETURN'] = "editsavedreport_return"; $content['REPORT_SENDBUTTON'] = $content['LN_REPORTS_EDITSAVEDREPORT']; + $content['REPORT_SENDANDRETURN'] = $content['LN_REPORTS_EDITSAVEDREPORTANDRETURN']; + if ( isset($_GET['id']) ) { @@ -977,7 +983,6 @@ if ( isset($_POST['op']) ) // Get ReportID! if ( isset($_POST['id']) ) { $content['ReportID'] = DB_RemoveBadChars($_POST['id']); } else {$content['ReportID'] = ""; } - // Only Continue if reportid is valud! if ( isset($content['REPORTS'][ $content['ReportID'] ]) ) { @@ -1092,7 +1097,7 @@ if ( isset($_POST['op']) ) if ( !isset($content['ISERROR']) ) { // Everything was alright, so we go to the next step! - if ( $_POST['op'] == "addsavedreport" ) + if ( strpos($_POST['op'], "addsavedreport") !== false ) { // Add custom search now! $sqlquery = "INSERT INTO " . DB_SAVEDREPORTS . " (reportid, sourceid, customTitle, customComment, filterString, customFilters, outputFormat, outputTarget, outputTargetDetails, scheduleSettings) @@ -1107,14 +1112,29 @@ if ( isset($_POST['op']) ) '" . $content['outputTargetDetails'] . "', '" . $content['scheduleSettings'] . "' )"; - + // Perform INSERT $result = DB_Query($sqlquery); + + // Get INSERTID from query! + $lastInsertID = mysql_insert_id(); + + // free ressources DB_FreeQuery($result); // Do the final redirect - RedirectResult( GetAndReplaceLangStr( $content['LN_REPORTS_HASBEENADDED'], DB_StripSlahes($content['customTitle']) ) , "reports.php" ); + if ( strpos($_POST['op'], "_return") !== false ) + RedirectResult( GetAndReplaceLangStr( $content['LN_REPORTS_HASBEENADDED'], DB_StripSlahes($content['customTitle']) ) , "reports.php" ); + else + { + // Correct FormUrlAddUrl! + $szRediUrl = str_replace( "op=addsavedreport", "op=editsavedreport", $content['FormUrlAddOP']); + $szRediUrl .= "&savedreportid=" . $lastInsertID; + + // Redirect to editpage! + RedirectResult( GetAndReplaceLangStr( $content['LN_REPORTS_HASBEENADDED'], DB_StripSlahes($content['customTitle']) ) , "reports.php" . $szRediUrl ); + } } - else if ( $_POST['op'] == "editsavedreport" ) + else if ( strpos($_POST['op'], "editsavedreport") !== false ) { $result = DB_Query("SELECT ID FROM " . DB_SAVEDREPORTS . " WHERE ID = " . $content['SavedReportID']); $myrow = DB_GetSingleRow($result, true); @@ -1141,7 +1161,10 @@ if ( isset($_POST['op']) ) DB_FreeQuery($result); // Done redirect! - RedirectResult( GetAndReplaceLangStr( $content['LN_REPORTS_HASBEENEDIT'], DB_StripSlahes($content['customTitle']) ) , "reports.php" ); + if ( strpos($_POST['op'], "_return") !== false ) + RedirectResult( GetAndReplaceLangStr( $content['LN_REPORTS_HASBEENEDIT'], DB_StripSlahes($content['customTitle']) ) , "reports.php" ); + else + RedirectResult( GetAndReplaceLangStr( $content['LN_REPORTS_HASBEENEDIT'], DB_StripSlahes($content['customTitle']) ) , "reports.php" . $content['FormUrlAddOP'] ); } } @@ -1268,6 +1291,9 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID) foreach ($_POST as $varname => $varvalue) $content['POST_VARIABLES'][] = array( "varname" => $varname, "varvalue" => $varvalue ); + // Append Force Optimice Paramater + $content['MSG_CHECK_URL'] .= "forcecheckoptimize=true"; + // Check if optimize variable is set! if ( isset($_GET['optimize']) ) { @@ -1367,44 +1393,64 @@ function CheckConfiguredLogStreamSource($myReport, $mySourceID) } } - $res = $myReportObj->CheckLogStreamSource( $mySourceID ); - if ( $res != SUCCESS ) + // Use SESSION to check if Source needs to be checked for optimization + $bForceCheck = false; + if ( !isset($_SESSION['Sources'][$mySourceID]['optimized']) || + $_SESSION['Sources'][$mySourceID]['optimized'] == false || + ( isset($_GET['forcecheckoptimize']) && $_GET['forcecheckoptimize'] == "true" ) + ) + // Set Checking to true! + $bForceCheck = true; + + // Lets see if we need to check + if ( $bForceCheck ) { - // Current Logstream Source is not optimized! Show to user! - $content['ISSOURCENOTOPTIMIZED'] = true; - if ( $res == ERROR_DB_DBFIELDNOTFOUND ) + // Run checks + $res = $myReportObj->CheckLogStreamSource( $mySourceID ); + if ( $res != SUCCESS ) { - $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 + // Current Logstream Source is not optimized! Show to user! + $content['ISSOURCENOTOPTIMIZED'] = true; + 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"; // Add missing INDEXES + } + else if ( $res == ERROR_DB_TRIGGERMISSING ) + { + $content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_PERFORMANCE_WARNING']; + $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"; // 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! + } } - else if ( $res == ERROR_DB_INDEXESMISSING ) + else { - $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"; // Add missing INDEXES - } - else if ( $res == ERROR_DB_TRIGGERMISSING ) - { - $content['MSG_WARNING_TITLE'] = $content['LN_REPORTS_PERFORMANCE_WARNING']; - $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"; // 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! + // Check was successfull! Set Checked Property in LogStream Source + $_SESSION['Sources'][$mySourceID]['optimized'] = true; } } + } diff --git a/src/lang/de/admin.php b/src/lang/de/admin.php index a95b4b7..1de0ccf 100644 --- a/src/lang/de/admin.php +++ b/src/lang/de/admin.php @@ -395,14 +395,8 @@ $content['LN_CMD_'] = ""; // Report Options $content['LN_REPORTS_EDIT'] = "Edit Report"; $content['LN_REPORTS_DELETE'] = "Remove Report"; -$content['LN_REPORTS_CAT'] = "Report Category"; -$content['LN_REPORTS_ID'] = "Report ID"; -$content['LN_REPORTS_NAME'] = "Report Name"; -$content['LN_REPORTS_DESCRIPTION'] = "Report Description"; $content['LN_REPORTS_REQUIREDFIELDS'] = "Required Fields"; $content['LN_REPORTS_ERROR_NOREPORTS'] = "There were no valid reports found in your installation."; -$content['LN_REPORTS_HELP'] = "Help"; -$content['LN_REPORTS_HELP_CLICK'] = "Click here for a detailed report description"; $content['LN_REPORTS_INFO'] = "Show more Information"; $content['LN_REPORTS_INIT'] = "Initialize settings"; $content['LN_REPORTS_REMOVE'] = "Remove settings"; @@ -414,8 +408,6 @@ $content['LN_REPORTS_ERROR_HASBEENREMOVED'] = "All settings for the report '%1' $content['LN_REPORTS_ERROR_HASBEENADDED'] = "All required settings for the report '%1' have been added."; $content['LN_REPORTS_ERROR_NOFIELDS'] = "The report '%1' does not have any custom settings which can be added."; $content['LN_REPORTS_ERROR_REPORTDOESNTNEEDTOBEREMOVED'] = "The report '%1' does not need to be removed or initialized."; -$content['LN_REPORTS_ADDSAVEDREPORT'] = "Add Savedreport"; -$content['LN_REPORTS_EDITSAVEDREPORT'] = "Edit Savedreport"; $content['LN_REPORTS_REMOVESAVEDREPORT'] = "Remove Savedreport"; $content['LN_REPORTS_CUSTOMTITLE'] = "Report Title"; $content['LN_REPORTS_CUSTOMCOMMENT'] = "Comment / Description"; @@ -427,7 +419,6 @@ $content['LN_REPORTS_HASBEENEDIT'] = "The Savedreport '%1' has been successfully $content['LN_REPORTS_SOURCEID'] = "Logstream source"; $content['LN_REPORTS_ERROR_SAVEDREPORTIDNOTFOUND'] = "There was no savedreport with ID '%1' found."; $content['LN_REPORTS_ERROR_INVALIDSAVEDREPORTID'] = "Invalid savedreport id."; -$content['LN_REPORTS_SAVEDREPORTS'] = "Saved reports"; $content['LN_REPORTS_RUNNOW'] = "Run saved report now!"; $content['LN_REPORTS_WARNDELETESAVEDREPORT'] = "Are you sure that you want to delete the savedreport '%1'?"; $content['LN_REPORTS_ERROR_DELSAVEDREPORT'] = "Deleting of the savedreport with id '%1' failed!"; @@ -447,16 +438,36 @@ $content['LN_REPORTS_ADVANCEDFILTERLIST'] = "List of advanced report filters"; $content['LN_REPORTS_OUTPUTTARGET_DETAILS'] = "Outputtarget Options"; $content['LN_REPORTS_OUTPUTTARGET_FILE'] = "Output Path and Filename"; $content['LN_REPORTS_CRONCMD'] = "Local Report command"; -$content['LN_REPORTMENU_LIST'] = "List installed Reports"; -$content['LN_REPORTMENU_ONLINELIST'] = "All Available Reports"; $content['LN_REPORTS_LINKS'] = "Related Links"; $content['LN_REPORTS_INSTALLED'] = "Installed"; $content['LN_REPORTS_NOTINSTALLED'] = "Not installed"; $content['LN_REPORTS_DOWNLOAD'] = "Download Link"; $content['LN_REPORTS_SAMPLELINK'] = "Report Sample"; $content['LN_REPORTS_DETAILSFOR'] = "Details for '%1' report"; -$content['LN_REPORTS_'] = ""; -$content['LN_REPORTS_'] = ""; +$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.

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.

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!

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.

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_RECHECKLOGSTREAMSOURCE'] = "Do you want to check the current logstream source again?"; +$content['LN_REPORTS_ADDSAVEDREPORT'] = "Add Savedreport and save changes"; +$content['LN_REPORTS_EDITSAVEDREPORT'] = "Save changes"; +$content['LN_REPORTS_ADDSAVEDREPORTANDRETURN'] = "Add Savedreport and return to reportlist"; +$content['LN_REPORTS_EDITSAVEDREPORTANDRETURN'] = "Save changes and return to reportlist"; $content['LN_REPORTS_'] = ""; ?> \ No newline at end of file diff --git a/src/lang/de/main.php b/src/lang/de/main.php index d1d2b34..7e044c2 100644 --- a/src/lang/de/main.php +++ b/src/lang/de/main.php @@ -328,28 +328,46 @@ $content['LN_ORACLE_FIELD'] = "Feld"; $content['LN_ORACLE_ONLINESEARCH'] = "Online Suche"; $content['LN_ORACLE_WHOIS'] = "WHOIS Abfrage für '%1' - '%2'"; - $content['LN_GEN_ERROR_INVALIDOP'] = "Invalid or missing operation type"; - $content['LN_GEN_ERROR_INVALIDREPORTID'] = "Invalid or missing report id"; - $content['LN_GEN_ERROR_MISSINGSAVEDREPORTID'] = "Invalid or missing savedreport id"; - $content['LN_GEN_ERROR_REPORTGENFAILED'] = "Failed generating report '%1' with the following error reason: %2"; - $content['LN_GEN_ERROR_WHILEREPORTGEN'] = "Error occured while generating report"; - $content['LN_GEN_ERROR_REPORT_NODATA'] = "No data found for report generation"; - $content['LN_GEN_ALL_OTHER_EVENTS'] = "All other events"; - $content['LN_REPORT_FOOTER_ENDERED'] = "Report rendered in"; - $content['LN_REPORT_FILTERS'] = "List of used filters"; - $content['LN_REPORT_FILTERTYPE_DATE'] = "Date"; - $content['LN_REPORT_FILTERTYPE_NUMBER'] = "Number"; - $content['LN_REPORT_FILTERTYPE_STRING'] = "String"; - $content['LN_GEN_SUCCESS_WHILEREPORTGEN'] = "Report was successfully generated"; - $content['LN_GEN_ERROR_REPORTFAILEDTOGENERATE'] = "Failed to generate report, error details: %1"; - $content['LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS'] = "Successfully generated report: %1"; +$content['LN_GEN_ERROR_INVALIDOP'] = "Invalid or missing operation type"; +$content['LN_GEN_ERROR_INVALIDREPORTID'] = "Invalid or missing report id"; +$content['LN_GEN_ERROR_MISSINGSAVEDREPORTID'] = "Invalid or missing savedreport id"; +$content['LN_GEN_ERROR_REPORTGENFAILED'] = "Failed generating report '%1' with the following error reason: %2"; +$content['LN_GEN_ERROR_WHILEREPORTGEN'] = "Error occured while generating report"; +$content['LN_GEN_ERROR_REPORT_NODATA'] = "No data found for report generation"; +$content['LN_GEN_ALL_OTHER_EVENTS'] = "All other events"; +$content['LN_REPORT_FOOTER_ENDERED'] = "Report rendered in"; +$content['LN_REPORT_FILTERS'] = "List of used filters"; +$content['LN_REPORT_FILTERTYPE_DATE'] = "Date"; +$content['LN_REPORT_FILTERTYPE_NUMBER'] = "Number"; +$content['LN_REPORT_FILTERTYPE_STRING'] = "String"; +$content['LN_GEN_SUCCESS_WHILEREPORTGEN'] = "Report was successfully generated"; +$content['LN_GEN_ERROR_REPORTFAILEDTOGENERATE'] = "Failed to generate report, error details: %1"; +$content['LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS'] = "Successfully generated report: %1"; - $content['LN_CMD_RUNREPORT'] = "Generating saved report '%1'"; - $content['LN_CMD_REPORTIDNOTFOUND'] = "Invalid Report ID '%1'"; - $content['LN_CMD_SAVEDREPORTIDNOTFOUND'] = "Invalid SavedReport ID '%1'"; - $content['LN_CMD_NOREPORTID'] = "Missing Report ID"; - $content['LN_CMD_NOSAVEDREPORTID'] = "Missing SavedReport ID"; - $content['LN_CMD_NOCMDPROMPT'] = "Error, this script can only be run from the command prompt."; +$content['LN_CMD_RUNREPORT'] = "Generating saved report '%1'"; +$content['LN_CMD_REPORTIDNOTFOUND'] = "Invalid Report ID '%1'"; +$content['LN_CMD_SAVEDREPORTIDNOTFOUND'] = "Invalid SavedReport ID '%1'"; +$content['LN_CMD_NOREPORTID'] = "Missing Report ID"; +$content['LN_CMD_NOSAVEDREPORTID'] = "Missing SavedReport ID"; +$content['LN_CMD_NOCMDPROMPT'] = "Error, this script can only be run from the command prompt."; $content['LN_REPORT_GENERATEDTIME'] = "Report generated at: "; +$content['LN_REPORT_ACTIONS'] = "Run Report Actions"; +$content['LN_REPORTS_CAT'] = "Report Category"; +$content['LN_REPORTS_ID'] = "Report ID"; +$content['LN_REPORTS_NAME'] = "Report Name"; +$content['LN_REPORTS_DESCRIPTION'] = "Report Description"; +$content['LN_REPORTS_HELP'] = "Help"; +$content['LN_REPORTS_HELP_CLICK'] = "Click here for a detailed report description"; +$content['LN_REPORTS_INFO'] = "Show more Information"; +$content['LN_REPORTS_SAVEDREPORTS'] = "Saved reports"; +$content['LN_REPORTS_ADMIN'] = "Administrate Reports"; +$content['LN_REPORTMENU_LIST'] = "List installed Reports"; +$content['LN_REPORTMENU_ONLINELIST'] = "All Available Reports"; +$content['LN_REPORTS_INFORMATION'] = "This page shows a list of installed and available reports including saved report configurations. +
To run a report, click on the buttons right to the Saved Reports. +
Attention! Generating reports can be very time consuming depending on the size of your database. +"; +$content['LN_REPORTS_CHECKLOGSTREAMSOURCE'] = "Verify Logstream optimization"; + ?> \ No newline at end of file diff --git a/src/lang/en/admin.php b/src/lang/en/admin.php index c886fe9..63933d1 100644 --- a/src/lang/en/admin.php +++ b/src/lang/en/admin.php @@ -419,8 +419,6 @@ $content['LN_REPORTS_ERROR_HASBEENREMOVED'] = "All settings for the report '%1' $content['LN_REPORTS_ERROR_HASBEENADDED'] = "All required settings for the report '%1' have been added."; $content['LN_REPORTS_ERROR_NOFIELDS'] = "The report '%1' does not have any custom settings which can be added."; $content['LN_REPORTS_ERROR_REPORTDOESNTNEEDTOBEREMOVED'] = "The report '%1' does not need to be removed or initialized."; -$content['LN_REPORTS_ADDSAVEDREPORT'] = "Add Savedreport"; -$content['LN_REPORTS_EDITSAVEDREPORT'] = "Edit Savedreport"; $content['LN_REPORTS_REMOVESAVEDREPORT'] = "Remove Savedreport"; $content['LN_REPORTS_CUSTOMTITLE'] = "Report Title"; $content['LN_REPORTS_CUSTOMCOMMENT'] = "Comment / Description"; @@ -477,6 +475,10 @@ $content['LN_REPORTS_ERROR_FAILED_ADDING_FIELDS'] = "Failed adding missing dataf $content['LN_REPORTS_FIELDS_CREATED'] = "Added missing datafields"; $content['LN_REPORTS_FIELDS_CREATED_SUCCESS'] = "Successfully added missing datafields for datasource '%1'."; $content['LN_REPORTS_RECHECKLOGSTREAMSOURCE'] = "Do you want to check the current logstream source again?"; +$content['LN_REPORTS_ADDSAVEDREPORT'] = "Add Savedreport and save changes"; +$content['LN_REPORTS_EDITSAVEDREPORT'] = "Save changes"; +$content['LN_REPORTS_ADDSAVEDREPORTANDRETURN'] = "Add Savedreport and return to reportlist"; +$content['LN_REPORTS_EDITSAVEDREPORTANDRETURN'] = "Save changes and return to reportlist"; $content['LN_REPORTS_'] = ""; diff --git a/src/lang/en/main.php b/src/lang/en/main.php index 8f022b4..dc7ecbe 100644 --- a/src/lang/en/main.php +++ b/src/lang/en/main.php @@ -380,5 +380,7 @@ $content['LN_REPORTS_INFORMATION'] = "This page shows a list of installed and av
To run a report, click on the buttons right to the Saved Reports.
Attention! Generating reports can be very time consuming depending on the size of your database. "; +$content['LN_REPORTS_CHECKLOGSTREAMSOURCE'] = "Verify Logstream optimization"; + ?> \ No newline at end of file diff --git a/src/templates/admin/admin_reports.html b/src/templates/admin/admin_reports.html index d9302f1..02159ce 100644 --- a/src/templates/admin/admin_reports.html +++ b/src/templates/admin/admin_reports.html @@ -464,6 +464,8 @@ + {LN_REPORTS_CHECKLOGSTREAMSOURCE} + @@ -509,6 +511,7 @@ + From 43af76c3ccfda67538b0631eb7ff0ac67c152e34 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 10 Nov 2011 14:01:46 +0100 Subject: [PATCH 21/23] Added changelog entry for 3.3.0 --- ChangeLog | 31 +++++++++++++++++++++++++++++++ src/include/functions_common.php | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 274e669..9494afc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,35 @@ --------------------------------------------------------------------------- +Version 3.3.0 (beta), 2011-11-?? +- Added more debug output at critical areas. +- New view for Reports in main area. The new view is simular to the + statistics page and makes the report more aware and accessable to + loganalyzer users. The reports are still edited in the Admin Center. +- Syslog/Eventlog Summary Report - both reports have been upgraded to V2! + The "Event Count" column has been moved to the left of the report. + The report use logstream functions now to generate the report data. + This has a huge positive impact on performance of database logstream + sources. Checksum calculation needed to consolidate messages is now + done by the logstream source. +- Fixed bug with filter edit handling in report admin +- Added function to generate missing checksums for all messages in + logstream reports. This means first time you generate a report could + take a little bit longer then usual. +- Some cosmetic changes in Syslog/Eventlog Summary report templates. +- Added optimization check into logstream sources. This check is + automatically performed by the report admin. If Fields, Indexes + or Triggers are missing, the report admin will inform you and give you + the possibility optimize the logstream source. These checks are supported + for Mysql, PostgreSQL and MSSQL only. Loganalyzer will need ALTER TABLE + rights in order to fix or optimize the database structure. + Indexes added by the a Report will enhance generation time as the + involved fields are used for grouping or sorting. Triggers are used + to generate the message checksum when a new data record is INSERTED + into the database. +- Changed mininum width of context menu on mainpage from + 200 to 250px due display problems in some browsers. +- Savedreports in Report Admin can now be saved only. This is useful + to check the logstream source after change for optimization. +--------------------------------------------------------------------------- Version 3.2.3 (stable), 2011-11-08 - Removed magic quotes check from database functions (obselete due the changes in the last version) diff --git a/src/include/functions_common.php b/src/include/functions_common.php index 888eb2f..bd676dd 100644 --- a/src/include/functions_common.php +++ b/src/include/functions_common.php @@ -66,7 +66,7 @@ $LANG_EN = "en"; // Used for fallback $LANG = "en"; // Default language // Default Template vars -$content['BUILDNUMBER'] = "3.2.3"; +$content['BUILDNUMBER'] = "3.3.0"; $content['UPDATEURL'] = "http://loganalyzer.adiscon.com/files/version.txt"; $content['TITLE'] = "Adiscon LogAnalyzer :: Release " . $content['BUILDNUMBER']; // Default page title $content['BASEPATH'] = $gl_root_path; From 98a0d218163b95a8387b8d006e967c1bb76902f5 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Thu, 10 Nov 2011 14:08:25 +0100 Subject: [PATCH 22/23] Added missing include file for report overview functions_reports.php --- src/include/functions_reports.php | 264 ++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 src/include/functions_reports.php diff --git a/src/include/functions_reports.php b/src/include/functions_reports.php new file mode 100644 index 0000000..8e52325 --- /dev/null +++ b/src/include/functions_reports.php @@ -0,0 +1,264 @@ + * + * * + * All directives are explained within this file * + * + * Copyright (C) 2008-2011 Adiscon GmbH. + * + * This file is part of LogAnalyzer. + * + * LogAnalyzer is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LogAnalyzer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LogAnalyzer. If not, see . + * + * A copy of the GPL can be found in the file "COPYING" in this + * distribution. + ********************************************************************* +*/ + +// --- Avoid directly accessing this file! +if ( !defined('IN_PHPLOGCON') ) +{ + die('Hacking attempt'); + exit; +} +// --- + +// --- +// --- BEGIN Helper functions +// --- +function CreateCronCommand( $myReportID, $mySavedReportID = null ) +{ + global $content, $gl_root_path, $myReport; + + if ( isset($mySavedReportID) ) + { + // Get Reference to report! + $myReport = $content['REPORTS'][ $myReportID ]; + + // Get reference to savedreport + $mySavedReport = $myReport['SAVEDREPORTS'][ $mySavedReportID ]; + + // Get configured Source for savedreport + $myReportSource = null; + if ( isset($content['Sources'][ $mySavedReport['sourceid'] ]) ) + $myReportSource = $content['Sources'][ $mySavedReport['sourceid'] ]; + + $pos = strpos( strtoupper(PHP_OS), "WIN"); + if ($pos !== false) + { + // Running on Windows + $phpCmd = PHP_BINDIR . "\\php.exe"; + $phpScript = realpath($gl_root_path) . "cron\\cmdreportgen.php"; + } + else + { + // Running on LINUX + $phpCmd = PHP_BINDIR . "/php"; + $phpScript = realpath($gl_root_path) . "/cron/cmdreportgen.php"; + } + + // Enable display of report command + $content['enableCronCommand'] = true; + $szCommand = $phpCmd . " " . $phpScript . " runreport " . $myReportID . " " . $mySavedReportID; + + // --- Check for user or group sources + if ( $myReportSource['userid'] != null ) + { + $szCommand .= " " . "userid=" . $myReportSource['userid']; + } + else if ( $myReportSource['groupid'] != null ) + { + $szCommand .= " " . "groupid=" . $myReportSource['groupid']; + } + // --- + } + else + { + // Disable display of report command + $content['enableCronCommand'] = false; + $szCommand = ""; + } + + // return result + return $szCommand; +} + +function InitOnlineReports() +{ + global $content; + + $xmlArray = xml2array( URL_ONLINEREPORTS ); + if ( is_array($xmlArray) && isset($xmlArray['reports']['report']) && count($xmlArray['reports']['report']) > 0 ) + { + foreach( $xmlArray['reports']['report'] as $myOnlineReport ) + { + // Copy to OnlineReports Array + $content['ONLINEREPORTS'][] = $myOnlineReport; + } + + // Success! + return true; + } + else + // Failure + return false; +} + +// Helper function from php doc +function xml2array($url, $get_attributes = 1, $priority = 'tag') +{ + $contents = ""; + if (!function_exists('xml_parser_create')) + { + return false; + } + $parser = xml_parser_create(''); + if (!($fp = @ fopen($url, 'rb'))) + { + return false; + } + while (!feof($fp)) + { + $contents .= fread($fp, 8192); + } + fclose($fp); + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + xml_parse_into_struct($parser, trim($contents), $xml_values); + xml_parser_free($parser); + if (!$xml_values) + return; //Hmm... + $xml_array = array (); + $parents = array (); + $opened_tags = array (); + $arr = array (); + $current = & $xml_array; + $repeated_tag_index = array (); + foreach ($xml_values as $data) + { + unset ($attributes, $value); + extract($data); + $result = array (); + $attributes_data = array (); + if (isset ($value)) + { + if ($priority == 'tag') + $result = $value; + else + $result['value'] = $value; + } + if (isset ($attributes) and $get_attributes) + { + foreach ($attributes as $attr => $val) + { + if ($priority == 'tag') + $attributes_data[$attr] = $val; + else + $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' + } + } + if ($type == "open") + { + $parent[$level -1] = & $current; + if (!is_array($current) or (!in_array($tag, array_keys($current)))) + { + $current[$tag] = $result; + if ($attributes_data) + $current[$tag . '_attr'] = $attributes_data; + $repeated_tag_index[$tag . '_' . $level] = 1; + $current = & $current[$tag]; + } + else + { + if (isset ($current[$tag][0])) + { + $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; + $repeated_tag_index[$tag . '_' . $level]++; + } + else + { + $current[$tag] = array ( + $current[$tag], + $result + ); + $repeated_tag_index[$tag . '_' . $level] = 2; + if (isset ($current[$tag . '_attr'])) + { + $current[$tag]['0_attr'] = $current[$tag . '_attr']; + unset ($current[$tag . '_attr']); + } + } + $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; + $current = & $current[$tag][$last_item_index]; + } + } + elseif ($type == "complete") + { + if (!isset ($current[$tag])) + { + $current[$tag] = $result; + $repeated_tag_index[$tag . '_' . $level] = 1; + if ($priority == 'tag' and $attributes_data) + $current[$tag . '_attr'] = $attributes_data; + } + else + { + if (isset ($current[$tag][0]) and is_array($current[$tag])) + { + $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; + if ($priority == 'tag' and $get_attributes and $attributes_data) + { + $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; + } + $repeated_tag_index[$tag . '_' . $level]++; + } + else + { + $current[$tag] = array ( + $current[$tag], + $result + ); + $repeated_tag_index[$tag . '_' . $level] = 1; + if ($priority == 'tag' and $get_attributes) + { + if (isset ($current[$tag . '_attr'])) + { + $current[$tag]['0_attr'] = $current[$tag . '_attr']; + unset ($current[$tag . '_attr']); + } + if ($attributes_data) + { + $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; + } + } + $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken + } + } + } + elseif ($type == 'close') + { + $current = & $parent[$level -1]; + } + } + return ($xml_array); +} + + +?> \ No newline at end of file From 44c97f9e3e56b3bcb218bbaa04a7766d555c1780 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Mon, 14 Nov 2011 13:32:32 +0100 Subject: [PATCH 23/23] Finalized changelog entry for 3.0.0 beta --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9494afc..fc06780 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,5 @@ --------------------------------------------------------------------------- -Version 3.3.0 (beta), 2011-11-?? +Version 3.3.0 (beta), 2011-11-14 - Added more debug output at critical areas. - New view for Reports in main area. The new view is simular to the statistics page and makes the report more aware and accessable to