Fixed table detection method in PDO LogStream.

This fixes problems with the detection of available tables when using
syslogng tables in postgresql for example.

Also added support to parse date only values like "2009-03-24".
This commit is contained in:
Andre Lorbach 2009-03-24 16:01:04 +01:00
parent eeef8ad211
commit ff33514623
3 changed files with 56 additions and 26 deletions

View File

@ -139,6 +139,8 @@ class LogStreamPDO extends LogStream {
* @return integer Error state * @return integer Error state
*/ */
public function Verify() { public function Verify() {
global $content, $dbmapping;
// Create DSN String // Create DSN String
$myDBDriver = $this->_logStreamConfigObj->GetPDODatabaseType(); $myDBDriver = $this->_logStreamConfigObj->GetPDODatabaseType();
$myDsn = $this->_logStreamConfigObj->CreateConnectDSN(); $myDsn = $this->_logStreamConfigObj->CreateConnectDSN();
@ -150,7 +152,7 @@ class LogStreamPDO extends LogStream {
{ {
global $extraErrorDescription; global $extraErrorDescription;
$extraErrorDescription = "PDO Database Driver not loaded: " . $myDBDriver . "<br>Please check your php configuration extensions"; $extraErrorDescription = "PDO Database Driver not loaded: " . $myDBDriver . "<br>Please check your php configuration extensions";
// $this->PrintDebugError($extraErrorDescription); // OutputDebugMessage("LogStreamPDO|Verify: $extraErrorDescription", DEBUG_ERROR);
// return error code // return error code
return ERROR_DB_INVALIDDBDRIVER; return ERROR_DB_INVALIDDBDRIVER;
@ -165,17 +167,33 @@ class LogStreamPDO extends LogStream {
catch (PDOException $e) catch (PDOException $e)
{ {
global $extraErrorDescription; global $extraErrorDescription;
$extraErrorDescription = "PDO Database Connection failed: " . $e->getMessage() . "<br>DSN: " . $myDsn; $extraErrorDescription = "PDO Database Connection failed: " . $e->getMessage();
// $this->PrintDebugError($extraErrorDescription);
// Append extra data if admin user
if ( isset($content['SESSION_ISADMIN']) && $content['SESSION_ISADMIN'] )
$extraErrorDescription .= "<br>AdminDebug - DSN: " . $myDsn;
// Debug Output
// OutputDebugMessage("LogStreamPDO|Verify: $extraErrorDescription", DEBUG_ERROR);
// return error code // return error code
return ERROR_DB_CONNECTFAILED; return ERROR_DB_CONNECTFAILED;
} }
// Check if Table Mapping exists
if ( !isset($dbmapping[$this->_logStreamConfigObj->DBTableType]) )
{
// Return error
return ERROR_DB_INVALIDDBMAPPING;
}
// Check if table exists
try try
{ {
// This is one way to check if the table exists! But I don't really like it tbh -.- // This is one way to check if the table exists! But I don't really like it tbh -.-
$tmpStmnt = $this->_dbhandle->prepare("SELECT ID FROM " . $this->_logStreamConfigObj->DBTableName . " WHERE ID=1"); $szIdField = $dbmapping[$this->_logStreamConfigObj->DBTableType][SYSLOG_UID];
$szTestQuery = "SELECT MAX(" . $szIdField . ") FROM " . $this->_logStreamConfigObj->DBTableName;
$tmpStmnt = $this->_dbhandle->prepare( $szTestQuery );
$tmpStmnt->execute(); $tmpStmnt->execute();
$colcount = $tmpStmnt->columnCount(); $colcount = $tmpStmnt->columnCount();
if ( $colcount <= 0 ) if ( $colcount <= 0 )
@ -185,6 +203,7 @@ class LogStreamPDO extends LogStream {
{ {
global $extraErrorDescription; global $extraErrorDescription;
$extraErrorDescription = "Could not find table: " . $e->getMessage(); $extraErrorDescription = "Could not find table: " . $e->getMessage();
// OutputDebugMessage("LogStreamPDO|Verify: $extraErrorDescription", DEBUG_ERROR);
// return error code // return error code
return ERROR_DB_TABLENOTFOUND; return ERROR_DB_TABLENOTFOUND;

View File

@ -1146,6 +1146,14 @@ function GetEventTime($szTimStr)
$eventtime[EVTIME_TIMEZONE] = date_default_timezone_get(); // > WTF TODO! > $out[7] $eventtime[EVTIME_TIMEZONE] = date_default_timezone_get(); // > WTF TODO! > $out[7]
$eventtime[EVTIME_MICROSECONDS] = 0; $eventtime[EVTIME_MICROSECONDS] = 0;
} }
// Sample: 2008-02-19
else if ( preg_match("/([0-9]{4,4})-([0-9]{1,2})-([0-9]{1,2})/", $szTimStr, $out ) )
{
// RFC 3164 typical timestamp
$eventtime[EVTIME_TIMESTAMP] = mktime(0, 0, 0, $out[2], $out[3], $out[1]);
$eventtime[EVTIME_TIMEZONE] = date_default_timezone_get(); // WTF TODO!
$eventtime[EVTIME_MICROSECONDS] = 0;
}
else else
{ {
$eventtime[EVTIME_TIMESTAMP] = 0; $eventtime[EVTIME_TIMESTAMP] = 0;
@ -1160,6 +1168,31 @@ function GetEventTime($szTimStr)
return $eventtime; return $eventtime;
} }
/*
* Helper function to output debug messages
*/
function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO)
{
global $content;
// Check if we should print the Error!
if ( GetConfigSetting("MiscShowDebugMsg", 0, CFGLEVEL_USER) == 1 )
{
$content['DEBUGMSG'][] = array(
"DBGLEVEL" => $szDbgLevel,
"DBGLEVELTXT" => GetDebugModeString($szDbgLevel),
"DBGLEVELBG" => GetDebugBgColor($szDbgLevel),
"DBGMSG" => "$szDbg"
);
}
// Check if the user wants to syslog the error!
if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 )
{
syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg);
}
}
/* /*
* GetMonthFromString * GetMonthFromString
* *

View File

@ -232,28 +232,6 @@ function GetFormatedDate($evttimearray)
return $szDateFormatted = date("Y-m-d H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); return $szDateFormatted = date("Y-m-d H:i:s", $evttimearray[EVTIME_TIMESTAMP] );
} }
function OutputDebugMessage($szDbg, $szDbgLevel = DEBUG_INFO)
{
global $content;
// Check if we should print the Error!
if ( GetConfigSetting("MiscShowDebugMsg", 0, CFGLEVEL_USER) == 1 )
{
$content['DEBUGMSG'][] = array(
"DBGLEVEL" => $szDbgLevel,
"DBGLEVELTXT" => GetDebugModeString($szDbgLevel),
"DBGLEVELBG" => GetDebugBgColor($szDbgLevel),
"DBGMSG" => "$szDbg"
);
}
// Check if the user wants to syslog the error!
if ( GetConfigSetting("MiscDebugToSyslog", 0, CFGLEVEL_GLOBAL) == 1 )
{
syslog(GetPriorityFromDebugLevel($szDbgLevel), $szDbg);
}
}
function GetDebugBgColor( $szDebugMode ) function GetDebugBgColor( $szDebugMode )
{ {
global $severity_colors; global $severity_colors;