Implemented dynamic charts into the configuration system

This commit is contained in:
unknown 2008-09-11 13:17:02 +02:00
parent 9f695db852
commit 3a7826b6f8
11 changed files with 189 additions and 51 deletions

View File

@ -96,6 +96,18 @@ if ( isset($_GET['maxrecords']) )
if ( $content['maxrecords'] < 2 || $content['maxrecords'] > 100 )
$content['maxrecords'] = 10;
}
else
$content['maxrecords'] = 10;
if ( isset($_GET['showpercent']) )
{
// read and verify value
$content['showpercent'] = intval($_GET['showpercent']);
if ( $content['showpercent'] >= 1 )
$content['showpercent'] = 1;
else
$content['showpercent'] = 0;
}
else
$content['maxrecords'] = 10;
// ---

View File

@ -98,6 +98,13 @@ $CFG['Search'][] = array ( "DisplayName" => "All messages from last 31 days", "S
// $CFG['Search'][] = array ( "DisplayName" => "", "SearchQuery" => "" );
// ---
// --- Predefined Charts!
$CFG['Charts'][] = array ( "DisplayName" => "Top Hosts", "chart_type" => CHART_BARS_HORIZONTAL, "chart_width" => 400, "chart_field" => SYSLOG_HOST, "maxrecords" => 10, "showpercent" => 0 );
$CFG['Charts'][] = array ( "DisplayName" => "SyslogTags", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_SYSLOGTAG, "maxrecords" => 10, "showpercent" => 0 );
$CFG['Charts'][] = array ( "DisplayName" => "Severities", "chart_type" => CHART_BARS_VERTICAL, "chart_width" => 400, "chart_field" => SYSLOG_SEVERITY, "maxrecords" => 10, "showpercent" => 1 );
$CFG['Charts'][] = array ( "DisplayName" => "Date", "chart_type" => CHART_CAKE, "chart_width" => 400, "chart_field" => SYSLOG_DATE, "maxrecords" => 10, "showpercent" => 0 );
// ---
// --- Source Options
/* Example for DiskType Source:
$CFG['Sources']['Source1']['ID'] = "Source1";

View File

@ -61,6 +61,7 @@ define('ERROR_DB_TABLENOTFOUND', 17);
define('ERROR_DB_DBFIELDNOTFOUND', 19);
define('ERROR_MSG_NOMATCH', 18);
define('ERROR_CHARTS_NOTCONFIGURED', 20);
?>

View File

@ -109,3 +109,21 @@ CREATE TABLE IF NOT EXISTS `logcon_views` (
`groupid` int(11) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Stores custom defined user views.' AUTO_INCREMENT=1 ;
--
-- Table structure for table `logcon_charts`
--
DROP TABLE IF EXISTS `logcon_charts`;
CREATE TABLE IF NOT EXISTS `logcon_charts` (
`ID` int(11) NOT NULL auto_increment,
`DisplayName` varchar(255) NOT NULL,
`chart_type` int(11) NOT NULL,
`chart_width` int(11) NOT NULL,
`chart_field` varchar(255) NOT NULL,
`maxrecords` int(11) NOT NULL,
`showpercent` tinyint(1) NOT NULL,
`userid` int(11) default NULL,
`groupid` int(11) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='This table contains all configured charts' AUTO_INCREMENT=1 ;

View File

@ -0,0 +1,17 @@
-- New Database Structure Updates
CREATE TABLE IF NOT EXISTS `logcon_charts` (
`ID` int(11) NOT NULL auto_increment,
`DisplayName` varchar(255) NOT NULL,
`chart_type` int(11) NOT NULL,
`chart_width` int(11) NOT NULL,
`chart_field` varchar(255) NOT NULL,
`maxrecords` int(11) NOT NULL,
`showpercent` tinyint(1) NOT NULL,
`userid` int(11) default NULL,
`groupid` int(11) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='This table contains all configured charts' AUTO_INCREMENT=1 ;
-- Insert data
-- Updated Data

View File

@ -582,6 +582,9 @@ function InitConfigurationValues()
// Load Configured Searches
LoadSearchesFromDatabase();
// Load Configured Charts
LoadChartsFromDatabase();
// Load Configured Views
LoadViewsFromDatabase();
@ -1227,7 +1230,9 @@ function GetErrorMessage($errorCode)
return $content['LN_ERROR_DB_INVALIDDBDRIVER'];
case ERROR_DB_TABLENOTFOUND:
return $content['LN_ERROR_DB_TABLENOTFOUND'];
case ERROR_CHARTS_NOTCONFIGURED:
return $content['LN_ERROR_CHARTS_NOTCONFIGURED'];
default:
return GetAndReplaceLangStr( $content['LN_ERROR_UNKNOWN'], $errorCode );

View File

@ -314,6 +314,7 @@ function InitPhpLogConConfigFile($bHandleMissing = true)
define('DB_SOURCES', $tblPref . "sources");
define('DB_USERS', $tblPref . "users");
define('DB_VIEWS', $tblPref . "views");
define('DB_CHARTS', $tblPref . "charts");
// Legacy support for old columns definition format!
if ( isset($CFG['Columns']) && is_array($CFG['Columns']) )
@ -394,6 +395,58 @@ function LoadSearchesFromDatabase()
}
}
/*
* Helper function to load configured Searches from the database
*/
function LoadChartsFromDatabase()
{
// Needed to make global
global $CFG, $content;
// --- Create SQL Query
// Create Where for USERID
if ( isset($content['SESSION_LOGGEDIN']) && $content['SESSION_LOGGEDIN'] )
$szWhereUser = " OR " . DB_CHARTS . ".userid = " . $content['SESSION_USERID'] . " ";
else
$szWhereUser = "";
if ( isset($content['SESSION_GROUPIDS']) )
$szGroupWhere = " OR " . DB_CHARTS . ".groupid IN (" . $content['SESSION_GROUPIDS'] . ")";
else
$szGroupWhere = "";
$sqlquery = " SELECT " .
DB_CHARTS . ".ID, " .
DB_CHARTS . ".DisplayName, " .
DB_CHARTS . ".chart_type, " .
DB_CHARTS . ".chart_width, " .
DB_CHARTS . ".chart_field, " .
DB_CHARTS . ".maxrecords, " .
DB_CHARTS . ".showpercent, " .
DB_CHARTS . ".userid, " .
DB_CHARTS . ".groupid, " .
DB_USERS . ".username, " .
DB_GROUPS . ".groupname " .
" FROM " . DB_CHARTS .
" LEFT OUTER JOIN (" . DB_USERS . ") ON (" . DB_CHARTS . ".userid=" . DB_USERS . ".ID ) " .
" LEFT OUTER JOIN (" . DB_GROUPS . ") ON (" . DB_CHARTS . ".groupid=" . DB_GROUPS . ".ID ) " .
" WHERE (" . DB_CHARTS . ".userid IS NULL AND " . DB_CHARTS . ".groupid IS NULL) " .
$szWhereUser .
$szGroupWhere .
" ORDER BY " . DB_CHARTS . ".userid, " . DB_CHARTS . ".groupid, " . DB_CHARTS . ".DisplayName";
// ---
// Get Searches from DB now!
$result = DB_Query($sqlquery);
$myrows = DB_GetAllRows($result, true);
if ( isset($myrows ) && count($myrows) > 0 )
{
// Overwrite Search Array with Database one
$CFG['Charts'] = $myrows;
$content['Charts'] = $myrows;
}
}
function LoadViewsFromDatabase()
{
// Needed to make global

View File

@ -45,7 +45,7 @@ $errdesc = "";
$errno = 0;
// --- Current Database Version, this is important for automated database Updates!
$content['database_internalversion'] = "2"; // Whenever incremented, a database upgrade is needed
$content['database_internalversion'] = "3"; // Whenever incremented, a database upgrade is needed
$content['database_installedversion'] = "0"; // 0 is default which means Prior Versioning Database
// ---

View File

@ -87,6 +87,9 @@ function ConvertGeneralSettings()
SaveGeneralSettingsIntoDB();
}
/*
* Convert Custom searches into DB
*/
function ConvertCustomSearches()
{
global $CFG, $content;
@ -102,6 +105,34 @@ function ConvertCustomSearches()
}
}
/*
* Convert Custom Charts into DB
*/
function ConvertCustomCharts()
{
global $CFG, $content;
// Insert all searches into the DB!
foreach($CFG['Charts'] as $chartid => &$myChart)
{
// New Entry
$result = DB_Query("INSERT INTO " . DB_CHARTS . " (DisplayName, chart_type, chart_width, chart_field, maxrecords, showpercent)
VALUES (
'" . PrepareValueForDB($myChart['DisplayName']) . "',
" . intval($mySearch['chart_type']) . ",
" . intval($mySearch['chart_width']) . ",
'" . PrepareValueForDB($mySearch['chart_field']) . "',
" . intval($mySearch['maxrecords']) . ",
" . intval($mySearch['showpercent']) . "
)");
$myChart['DBID'] = DB_ReturnLastInsertID($result);
DB_FreeQuery($result);
}
}
/*
* Convert Custom Views into DB
*/
function ConvertCustomViews()
{
global $CFG, $content;

View File

@ -53,43 +53,44 @@ InitFilterHelpers(); // Helpers for frontend filtering!
// ---
// --- BEGIN Custom Code
/*if ( isset($content['Sources'][$currentSourceID]) )
if ( isset($content['Charts']) )
{
// Obtain and get the Config Object
$stream_config = $content['Sources'][$currentSourceID]['ObjRef'];
// This will enable to Stats View
$content['statsenabled'] = true;
// Create LogStream Object
$stream = $stream_config->LogStreamFactory($stream_config);
$res = $stream->Open( $content['AllColumns'], true );
if ( $res == SUCCESS )
// PreProcess Charts Array for display!
$i = 0; // Help counter!
foreach ($content['Charts'] as &$myChart )
{
// This will enable to Stats View
$content['statsenabled'] = "true";
}
else
{
// This will disable to Stats View and show an error message
$content['statsenabled'] = "false";
// Set error code
$content['error_code'] = $ret;
if ( $ret == ERROR_FILE_NOT_FOUND )
$content['detailederror'] = $content['LN_ERROR_FILE_NOT_FOUND'];
else if ( $ret == ERROR_FILE_NOT_READABLE )
$content['detailederror'] = $content['LN_ERROR_FILE_NOT_READABLE'];
else
$content['detailederror'] = $content['LN_ERROR_UNKNOWN'];
// --- Set CSS Class
if ( $i % 2 == 0 )
{
$myChart['cssclass'] = "line1";
$myChart['rowbegin'] = '<tr><td width="50%" valign="top">';
$myChart['rowend'] = '</td>';
}
else
{
$myChart['cssclass'] = "line2";
$myChart['rowbegin'] = '<td width="50%" valign="top">';
$myChart['rowend'] = '</td></tr>';
}
$i++;
// ---
}
// Close file!
$stream->Close();
}
*/
else
{
// This will disable to Stats View and show an error message
$content['statsenabled'] = false;
// Set error code
$content['ISERROR'] = true;
$content['ERROR_MSG'] = GetErrorMessage(ERROR_CHARTS_NOTCONFIGURED);
}
// ---
// --- BEGIN CREATE TITLE

View File

@ -12,32 +12,25 @@
<br><br>
<!-- ENDIF ISERROR="true" -->
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
<!-- IF statsenabled="true" -->
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border_alternative">
<tr>
<td colspan="3" class="title" nowrap><B>{LN_MENU_STATISTICS}</B></td>
</tr>
<tr>
<td width="50%" valign="top" class="line2">
<br><br>
<table width="400" cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td class="cellmenu1" align="center"><B>{LN_STATS_GRAPH}: {LN_STATS_COUNTBYSOURCE}</B></td></tr>
<tr><td class="line1"><img src="{BASEPATH}chartgenerator.php?type=2&byfield=FROMHOST&width=400&maxrecords=10" width="400" height="400"></td></tr>
<!-- BEGIN Charts -->
{rowbegin}
<br><br>
<table cellpadding="0" cellspacing="0" border="0" align="center" valign="top">
<tr><td class="cellmenu1" align="center"><B>{DisplayName}</B></td></tr>
<tr><td class="{cssclass}">
<img src="{BASEPATH}chartgenerator.php?type={chart_type}&byfield={chart_field}&width={chart_width}&maxrecords={maxrecords}" width="{chart_width}" height="{chart_width}">
</td></tr>
</table>
<br><br>
</td>
<td width="50%" valign="top" class="line2">
<br><br>
<table width="400" cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td class="cellmenu1" align="center"><B>{LN_STATS_GRAPH}: {LN_STATS_COUNTBYSYSLOGTAG}</B></td></tr>
<tr><td class="line1"><img src="{BASEPATH}chartgenerator.php?type=1&byfield=syslogtag&width=400&maxrecords=10" width="400" height="400"></td></tr>
</table>
<br><br>
</td>
</tr>
{rowend}
<!-- END Charts -->
</table>
<!-- ENDIF statsenabled="true" -->
<!-- INCLUDE include_footer.html -->