Initial added MongoDB Logstream sources.

First test went fine, however still lots of work todo ;)
This commit is contained in:
Andre Lorbach 2012-03-29 16:15:19 +02:00
parent c243c2cc5d
commit 2250e27e3f
11 changed files with 2276 additions and 6 deletions

View File

@ -346,7 +346,9 @@ if ( isset($_GET['op']) )
$content['SourceTypeName'] = $content['SOURCETYPES'][ $content['SourceType'] ]['DisplayName'];
// Fix Filename manually for FILE LOGSTREAM!
if ( $content['SourceType'] == SOURCE_DB || $content['SourceType'] == SOURCE_PDO )
if ( $content['SourceType'] == SOURCE_DB ||
$content['SourceType'] == SOURCE_PDO ||
$content['SourceType'] == SOURCE_MONGODB )
{
// Create LogStream Object
$stream = $tmpSource['ObjRef']->LogStreamFactory($tmpSource['ObjRef']);
@ -545,7 +547,10 @@ if ( isset($_POST['op']) )
if ( isset($_POST['SourceDiskFile']) ) { $content['SourceDiskFile'] = DB_RemoveBadChars($_POST['SourceDiskFile']); }
}
// DB Params
else if ( $content['SourceType'] == SOURCE_DB || $content['SourceType'] == SOURCE_PDO )
else if ( $content['SourceType'] == SOURCE_DB ||
$content['SourceType'] == SOURCE_PDO ||
$content['SourceType'] == SOURCE_MONGODB
)
{
if ( isset($_POST['SourceDBType']) ) { $content['SourceDBType'] = DB_RemoveBadChars($_POST['SourceDBType']); }
if ( isset($_POST['SourceDBName']) ) { $content['SourceDBName'] = DB_RemoveBadChars($_POST['SourceDBName']); }
@ -640,7 +645,10 @@ if ( isset($_POST['op']) )
}
}
// DB Params
else if ( $content['SourceType'] == SOURCE_DB || $content['SourceType'] == SOURCE_PDO )
else if ( $content['SourceType'] == SOURCE_DB ||
$content['SourceType'] == SOURCE_PDO ||
$content['SourceType'] == SOURCE_MONGODB
)
{
if ( !isset($content['SourceDBType']) )
{
@ -705,7 +713,10 @@ if ( isset($_POST['op']) )
$tmpSource['DiskFile'] = $content['SourceDiskFileTesting']; // use SourceDiskFileTesting rather then SourceDiskFile as it is corrected
}
// DB Params
else if ( $tmpSource['SourceType'] == SOURCE_DB || $tmpSource['SourceType'] == SOURCE_PDO )
else if ( $tmpSource['SourceType'] == SOURCE_DB ||
$tmpSource['SourceType'] == SOURCE_PDO ||
$tmpSource['SourceType'] == SOURCE_MONGODB
)
{
$tmpSource['DBType'] = DB_StripSlahes($content['SourceDBType']);
$tmpSource['DBName'] = DB_StripSlahes($content['SourceDBName']);
@ -761,7 +772,10 @@ if ( isset($_POST['op']) )
" . $content['groupid'] . "
)";
}
else if ( $content['SourceType'] == SOURCE_DB || $content['SourceType'] == SOURCE_PDO )
else if ( $content['SourceType'] == SOURCE_DB ||
$content['SourceType'] == SOURCE_PDO ||
$content['SourceType'] == SOURCE_MONGODB
)
{
$sqlquery = "INSERT INTO " . DB_SOURCES . " (Name, Description, SourceType, MsgParserList, MsgNormalize, MsgSkipUnparseable, defaultfilter, ViewID, DBTableType, DBType, DBServer, DBName, DBUser, DBPassword, DBTableName, DBEnableRowCounting, DBRecordsPerQuery, userid, groupid)
VALUES ('" . $content['Name'] . "',
@ -821,7 +835,10 @@ if ( isset($_POST['op']) )
groupid = " . $content['groupid'] . "
WHERE ID = " . $content['SOURCEID'];
}
else if ( $content['SourceType'] == SOURCE_DB || $content['SourceType'] == SOURCE_PDO )
else if ( $content['SourceType'] == SOURCE_DB ||
$content['SourceType'] == SOURCE_PDO ||
$content['SourceType'] == SOURCE_MONGODB
)
{
$sqlquery = "UPDATE " . DB_SOURCES . " SET
Name = '" . $content['Name'] . "',
@ -931,6 +948,15 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) )
// Enabled Database Maintenance functions
$mySource['IsDatabaseSource'] = true;
}
else if ( $mySource['SourceType'] == SOURCE_MONGODB )
{
$mySource['SourcesTypeImage'] = $content["MENU_SOURCE_MONGODB"];
$mySource['SourcesTypeText'] = $content["LN_SOURCES_MONGODB"];
// Enabled Database Maintenance functions
$mySource['IsDatabaseSource'] = true;
}
// ---
// --- Set CSS Class

View File

@ -0,0 +1,70 @@
<?php
/*
*********************************************************************
* LogAnalyzer - http://loganalyzer.adiscon.com
* ----------------------------------------------------------------- *
* StreamConfig has the capability to create a specific LogStream *
* object depending on a configured LogStream*Config object. *
* *
* All directives are explained within this file *
*
* Copyright (C) 2008-2010 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 <http://www.gnu.org/licenses/>.
*
* 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;
}
// ---
class LogStreamConfigMongoDB extends LogStreamConfig {
public $DBServer = '127.0.0.1';
public $DBPort = 27017;
public $DBName = 'syslog';
// public $DBUser = '';
// public $DBPassword = '';
public $DBTableType = 'mongodb'; // Default = Use mongodb layout!
public $DBCollection = 'rsyslog'; // Default Tabelname from RSYSLOG
// public $DBEnableRowCounting = true; // Default RowCounting is enabled!
// Runtime configuration variables
public $RecordsPerQuery = 100; // This will determine how to limit sql statements
public $IDsPerQuery = 5000; // When we query ID's, we read a lot more the datarecords at once!
public $SortColumn = SYSLOG_UID; // Default sorting column
// public $FileName = '';
// public $LineParserType = "syslog"; // Default = Syslog!
// public $_lineParser = null;
public function LogStreamFactory($o)
{
// An instance is created, then include the logstreamdisk class as well!
global $gl_root_path;
require_once($gl_root_path . 'classes/logstreammongodb.class.php');
// return LogStreamDisk instance
return new LogStreamMongoDB($o);
}
}
?>

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

View File

@ -71,6 +71,7 @@ define('CFGLEVEL_USER', 2);
define('SOURCE_DISK', '1');
define('SOURCE_DB', '2');
define('SOURCE_PDO', '3');
define('SOURCE_MONGODB', '4');
// ---
// --- Exportformat defines

View File

@ -376,6 +376,18 @@ $dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_MESSAGE] = "msg";
$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_SYSLOGTAG] = "tag";
$dbmapping['syslogng']['DBMAPPINGS'][SYSLOG_PROCESSID] = "program";
$dbmapping['mongodb']['ID'] = "mongodb";
$dbmapping['mongodb']['DisplayName'] = "MongoDB";
$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_UID] = "_id";
$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_DATE] = "time";
$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_HOST] = "sys";
$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_MESSAGE] = "msg";
// $dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_FACILITY] = "Facility";
$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_SEVERITY] = "level";
$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_SYSLOGTAG] = "procid";
//$dbmapping['mongodb']['DBMAPPINGS'][SYSLOG_PROCESSID] = "ProcessID";
$dbmapping['mongodb']['DBMAPPINGS'][MISC_CHECKSUM] = "Checksum";
// Convert all fieldnames to lowercase to avoid problems with case sensitive array keys later
foreach( $dbmapping as &$myMapping )
{

View File

@ -251,6 +251,11 @@ function CreateSourceTypesList( $selectedSource )
$content['SOURCETYPES'][SOURCE_PDO]['type'] = SOURCE_PDO;
$content['SOURCETYPES'][SOURCE_PDO]['DisplayName'] = $content['LN_GEN_SOURCE_PDO'];
if ( $selectedSource == $content['SOURCETYPES'][SOURCE_PDO]['type'] ) { $content['SOURCETYPES'][SOURCE_PDO]['selected'] = "selected"; } else { $content['SOURCETYPES'][SOURCE_PDO]['selected'] = ""; }
// SOURCE_MONGODB ( MONGODB Wrapper)
$content['SOURCETYPES'][SOURCE_MONGODB]['type'] = SOURCE_MONGODB;
$content['SOURCETYPES'][SOURCE_MONGODB]['DisplayName'] = $content['LN_GEN_SOURCE_MONGODB'];
if ( $selectedSource == $content['SOURCETYPES'][SOURCE_MONGODB]['type'] ) { $content['SOURCETYPES'][SOURCE_MONGODB]['selected'] = "selected"; } else { $content['SOURCETYPES'][SOURCE_MONGODB]['selected'] = ""; }
}
function CreateAuthTypesList( $selectedAuth )
@ -728,6 +733,7 @@ function InitFrontEndVariables()
$content['MENU_SOURCE_DISK'] = $content['BASEPATH'] . "images/icons/document_text.png";
$content['MENU_SOURCE_DB'] = $content['BASEPATH'] . "images/icons/data_table.png";
$content['MENU_SOURCE_PDO'] = $content['BASEPATH'] . "images/icons/data_gear.png";
$content['MENU_SOURCE_MONGODB'] = $content['BASEPATH'] . "images/icons/mongodb.png";
$content['MENU_MAXIMIZE'] = $content['BASEPATH'] . "images/icons/table_selection_all.png";
$content['MENU_NORMAL'] = $content['BASEPATH'] . "images/icons/table_selection_block.png";
$content['MENU_USEROPTIONS'] = $content['BASEPATH'] . "images/icons/businessman_preferences.png";

View File

@ -189,6 +189,23 @@ function InitSource(&$mysource)
if ( isset($mysource['DBPassword']) ) { $mysource['ObjRef']->DBPassword = $mysource['DBPassword']; }
if ( isset($mysource['DBEnableRowCounting']) ) { $mysource['ObjRef']->DBEnableRowCounting = $mysource['DBEnableRowCounting']; }
}
else if ( $mysource['SourceType'] == SOURCE_MONGODB)
{
// Perform necessary include
require_once($gl_root_path . 'classes/logstreamconfigmongodb.class.php');
$mysource['ObjRef'] = new LogStreamConfigMongoDB();
$mysource['ObjRef']->DBServer = $mysource['DBServer'];
$mysource['ObjRef']->DBName = $mysource['DBName'];
$mysource['ObjRef']->DBCollection = $mysource['DBTableName'];
$mysource['ObjRef']->DBTableType = strtolower($mysource['DBTableType']);
// Optional parameters!
if ( isset($mysource['DBPort']) ) { $mysource['ObjRef']->DBPort = $mysource['DBPort']; }
if ( isset($mysource['DBUser']) ) { $mysource['ObjRef']->DBUser = $mysource['DBUser']; }
if ( isset($mysource['DBPassword']) ) { $mysource['ObjRef']->DBPassword = $mysource['DBPassword']; }
// if ( isset($mysource['DBEnableRowCounting']) ) { $mysource['ObjRef']->DBEnableRowCounting = $mysource['DBEnableRowCounting']; }
}
else
{
// UNKNOWN, remove config entry!

View File

@ -256,6 +256,7 @@ $content['LN_SOURCES_ASSIGNTO'] = "Assigned To";
$content['LN_SOURCES_DISK'] = "Diskfile";
$content['LN_SOURCES_DB'] = "MySQL Database";
$content['LN_SOURCES_PDO'] = "PDO Datasource";
$content['LN_SOURCES_MONGODB'] = "MongoDB Datasource";
$content['LN_SOURCES_ADD'] = "Add new Source";
$content['LN_SOURCES_ADDEDIT'] = "Add / Edit a Source";
$content['LN_SOURCES_TYPE'] = "Source Type";

View File

@ -44,6 +44,7 @@ $content['LN_GEN_PREDEFINEDSEARCHES'] = "Predefined Searches";
$content['LN_GEN_SOURCE_DISK'] = "Diskfile";
$content['LN_GEN_SOURCE_DB'] = "MYSQL Native";
$content['LN_GEN_SOURCE_PDO'] = "Database (PDO)";
$content['LN_GEN_SOURCE_MONGODB'] = "MongoDB Native";
$content['LN_GEN_RECORDSPERPAGE'] = "records per page";
$content['LN_GEN_PRECONFIGURED'] = "Preconfigured";
$content['LN_GEN_AVAILABLESEARCHES'] = "Available searches";

View File

@ -25,6 +25,14 @@
showvisibility("HiddenDatabaseTypeOptions");
hidevisibility("HiddenDiskTypeOptions");
showvisibility("HiddenPDOSourceOptions");
hidevisibility("HiddenMYSQLSourceOptions");
}
else if (myfield.value == 4)
{
showvisibility("HiddenDatabaseTypeOptions");
hidevisibility("HiddenDiskTypeOptions");
showvisibility("HiddenPDOSourceOptions");
hidevisibility("HiddenMYSQLSourceOptions");
}