mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
Started implementing charts generator and statistic page
This commit is contained in:
parent
00456c2f0d
commit
7c0c12ca48
230
src/chartgenerator.php
Normal file
230
src/chartgenerator.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/*
|
||||
*********************************************************************
|
||||
* phpLogCon - http://www.phplogcon.org
|
||||
* -----------------------------------------------------------------
|
||||
* Export Code File
|
||||
*
|
||||
* -> This file will create gfx of charts, and handle image caching
|
||||
*
|
||||
* All directives are explained within this file
|
||||
*
|
||||
* Copyright (C) 2008 Adiscon GmbH.
|
||||
*
|
||||
* This file is part of phpLogCon.
|
||||
*
|
||||
* PhpLogCon 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.
|
||||
*
|
||||
* PhpLogCon 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 phpLogCon. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* A copy of the GPL can be found in the file "COPYING" in this
|
||||
* distribution
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
// *** Default includes and procedures *** //
|
||||
define('IN_PHPLOGCON', true);
|
||||
$gl_root_path = './';
|
||||
|
||||
// Now include necessary include files!
|
||||
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 LogStream facility
|
||||
include($gl_root_path . 'classes/logstream.class.php');
|
||||
|
||||
InitPhpLogCon();
|
||||
InitSourceConfigs();
|
||||
InitFrontEndDefaults(); // Only in WebFrontEnd
|
||||
InitFilterHelpers(); // Helpers for frontend filtering!
|
||||
// ---
|
||||
|
||||
// --- READ CONTENT Vars
|
||||
if ( isset($_GET['type']) )
|
||||
$content['chart_type'] = intval($_GET['type']);
|
||||
else
|
||||
$content['chart_type'] = CHART_CAKE;
|
||||
|
||||
if ( isset($_GET['width']) )
|
||||
$content['chart_width'] = intval($_GET['width']);
|
||||
else
|
||||
$content['chart_width'] = 100;
|
||||
|
||||
if ( isset($_GET['byfield']) )
|
||||
$content['chart_field'] = $_GET['byfield'];
|
||||
else
|
||||
{
|
||||
$content['error_occured'] = true;
|
||||
$content['error_details'] = $content['LN_GEN_ERROR_MISSINGCHARTFIELD'];
|
||||
}
|
||||
// ---
|
||||
|
||||
// --- BEGIN CREATE TITLE
|
||||
$content['TITLE'] = InitPageTitle();
|
||||
// --- END CREATE TITLE
|
||||
|
||||
// --- BEGIN Custom Code
|
||||
if ( !$content['error_occured'] )
|
||||
{
|
||||
if ( isset($content['Sources'][$currentSourceID]) )
|
||||
{
|
||||
// Obtain and get the Config Object
|
||||
$stream_config = $content['Sources'][$currentSourceID]['ObjRef'];
|
||||
|
||||
// Create LogStream Object
|
||||
$stream = $stream_config->LogStreamFactory($stream_config);
|
||||
|
||||
$res = $stream->Open( $content['Columns'], true );
|
||||
if ( $res == SUCCESS )
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// This will disable to Main SyslogView and show an error message
|
||||
$content['error_occured'] = true;
|
||||
$content['error_details'] = GetErrorMessage($res);
|
||||
if ( isset($extraErrorDescription) )
|
||||
$content['error_details'] .= "<br><br>" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription);
|
||||
}
|
||||
|
||||
// Close file!
|
||||
$stream->Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
$content['error_occured'] = true;
|
||||
$content['error_details'] = GetAndReplaceLangStr( $content['LN_GEN_ERROR_SOURCENOTFOUND'], $currentSourceID);
|
||||
}
|
||||
}
|
||||
// ---
|
||||
|
||||
// --- Convert and Output
|
||||
if ( $content['error_occured'] )
|
||||
{
|
||||
// TODO PRINT ERROR ON PICTURE STREAM!
|
||||
|
||||
// InitTemplateParser();
|
||||
// $page -> parser($content, "export.html");
|
||||
// $page -> output();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create ChartDiagram!
|
||||
|
||||
exit;
|
||||
|
||||
// Create a CVS File!
|
||||
$szOutputContent = "";
|
||||
$szOutputMimeType = "text/plain";
|
||||
$szOutputCharset = "";
|
||||
|
||||
$szOutputFileName = "ExportMessages";
|
||||
$szOutputFileExtension = ".txt";
|
||||
if ( $content['exportformat'] == EXPORT_CVS )
|
||||
{
|
||||
// Set MIME TYPE and File Extension
|
||||
$szOutputMimeType = "text/csv";
|
||||
$szOutputFileExtension = ".csv";
|
||||
|
||||
// Set Column line in cvs file!
|
||||
foreach($content['Columns'] as $mycolkey)
|
||||
{
|
||||
if ( isset($fields[$mycolkey]) )
|
||||
{
|
||||
// Prepend Comma if needed
|
||||
if (strlen($szOutputContent) > 0)
|
||||
$szOutputContent .= ",";
|
||||
|
||||
// Append column name
|
||||
$szOutputContent .= $content[ $fields[$mycolkey]['FieldCaptionID'] ];
|
||||
}
|
||||
}
|
||||
|
||||
// Append line break
|
||||
$szOutputContent .= "\n";
|
||||
|
||||
// Append messages into output
|
||||
foreach ( $content['syslogmessages'] as $myIndex => $mySyslogMessage )
|
||||
{
|
||||
$szLine = "";
|
||||
|
||||
// --- Process columns
|
||||
foreach($mySyslogMessage as $myColkey => $mySyslogField)
|
||||
{
|
||||
// Prepend Comma if needed
|
||||
if (strlen($szLine) > 0)
|
||||
$szLine .= ",";
|
||||
|
||||
// Append field contents
|
||||
$szLine .= '"' . str_replace('"', '\\"', $mySyslogField['fieldvalue']) . '"';
|
||||
}
|
||||
// ---
|
||||
|
||||
// Append line!
|
||||
$szOutputContent .= $szLine . "\n";
|
||||
}
|
||||
}
|
||||
else if ( $content['exportformat'] == EXPORT_XML )
|
||||
{
|
||||
// Set MIME TYPE and File Extension
|
||||
$szOutputMimeType = "application/xml";
|
||||
$szOutputFileExtension = ".xml";
|
||||
$szOutputCharset = "charset=UTF-8";
|
||||
|
||||
// Create XML Header and first node!!
|
||||
$szOutputContent .= "\xef\xbb\xbf";
|
||||
$szOutputContent .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
$szOutputContent .= "<syslogmessages>\n";
|
||||
|
||||
// Append messages into output
|
||||
foreach ( $content['syslogmessages'] as $myIndex => $mySyslogMessage )
|
||||
{
|
||||
$szXmlLine = "\t<syslogmsg>\n";
|
||||
|
||||
// --- Process columns
|
||||
foreach($mySyslogMessage as $myColkey => $mySyslogField)
|
||||
{
|
||||
|
||||
// if ( isset($content[ $fields[$mycolkey]['FieldCaptionID'] ]) )
|
||||
// $szNodeTitle = $content[ $fields[$mycolkey]['FieldCaptionID'] ];
|
||||
// else
|
||||
|
||||
// Append field content | first run htmlentities,tnen utf8 encoding!!
|
||||
$szXmlLine .= "\t\t<" . $myColkey . ">" . utf8_encode( htmlentities($mySyslogField['fieldvalue']) ) . "</" . $myColkey . ">\n";
|
||||
}
|
||||
// ---
|
||||
|
||||
$szXmlLine .= "\t</syslogmsg>\n";
|
||||
|
||||
// Append line!
|
||||
$szOutputContent .= $szXmlLine;
|
||||
}
|
||||
|
||||
// End first XML Node
|
||||
$szOutputContent .= "</syslogmessages>";
|
||||
}
|
||||
|
||||
// Set needed Header properties
|
||||
header('Content-type: ' . $szOutputMimeType . "; " . $szOutputCharset);
|
||||
header("Content-Length: " . strlen($szOutputContent) );
|
||||
header('Content-Disposition: attachment; filename="' . $szOutputFileName . $szOutputFileExtension . '"');
|
||||
|
||||
// Output Content!
|
||||
print( $szOutputContent );
|
||||
}
|
||||
// ---
|
||||
|
||||
?>
|
@ -348,12 +348,11 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['uid_current'
|
||||
$content['error_code'] = $ret;
|
||||
|
||||
if ( $ret == ERROR_FILE_NOT_FOUND )
|
||||
$content['detailederror'] = "Syslog file could not be found.";
|
||||
$content['detailederror'] = $content['LN_ERROR_FILE_NOT_FOUND'];
|
||||
else if ( $ret == ERROR_FILE_NOT_READABLE )
|
||||
$content['detailederror'] = "Syslog file is not readable, read access may be denied. ";
|
||||
$content['detailederror'] = $content['LN_ERROR_FILE_NOT_READABLE'];
|
||||
else
|
||||
$content['detailederror'] = "Unknown or unhandeled error occured.";
|
||||
|
||||
$content['detailederror'] = $content['LN_ERROR_UNKNOWN'];
|
||||
}
|
||||
|
||||
// Close file!
|
||||
|
@ -74,6 +74,12 @@ define('EXPORT_CVS', 'CVS');
|
||||
define('EXPORT_XML', 'XML');
|
||||
// ---
|
||||
|
||||
// --- GFX Chart Types
|
||||
define('CHART_CAKE', 1);
|
||||
define('CHART_BARS_VERTICAL', 2);
|
||||
define('CHART_BARS_HORIZONTAL', 3);
|
||||
// ---
|
||||
|
||||
// ---
|
||||
define('UID_UNKNOWN', -1);
|
||||
// ---
|
||||
|
@ -482,6 +482,7 @@ function InitFrontEndVariables()
|
||||
$content['MENU_NORMAL'] = $content['BASEPATH'] . "images/icons/table_selection_block.png";
|
||||
$content['MENU_USEROPTIONS'] = $content['BASEPATH'] . "images/icons/businessman_preferences.png";
|
||||
$content['MENU_EXPORT'] = $content['BASEPATH'] . "images/icons/export1.png";
|
||||
$content['MENU_CHARTS'] = $content['BASEPATH'] . "images/icons/line-chart.png";
|
||||
|
||||
$content['MENU_PAGER_BEGIN'] = $content['BASEPATH'] . "images/icons/media_beginning.png";
|
||||
$content['MENU_PAGER_PREVIOUS'] = $content['BASEPATH'] . "images/icons/media_rewind.png";
|
||||
|
@ -98,6 +98,7 @@ $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";
|
||||
|
||||
|
||||
// Index Site
|
||||
|
@ -98,6 +98,7 @@ $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";
|
||||
|
||||
// Main Index Site
|
||||
$content['LN_ERROR_INSTALLFILEREMINDER'] = "Warning! You still have NOT removed the 'install.php' from your phpLogCon main directory!";
|
||||
@ -278,5 +279,9 @@ $content['LN_CONVERT_STEP6_TEXT'] = 'Congratulations! You have successfully conv
|
||||
$content['LN_CONVERT_PROCESS'] = "Conversion Progress:";
|
||||
$content['LN_CONVERT_ERROR_SOURCEIMPORT'] = "Critical Error while importing the sources into the database, the SourceType '%1' is not supported by this phpLogCon Version.";
|
||||
|
||||
// Stats Site
|
||||
$content['LN_STATS_COUNTBYSOURCE'] = "Messagecount by Source";
|
||||
$content['LN_STATS_GRAPH'] = "Graph";
|
||||
|
||||
|
||||
?>
|
@ -103,6 +103,7 @@ $content['LN_ERROR_NORECORDS'] = "Sem mensagens encontradas.";
|
||||
$content['LN_MENU_LOGGEDINAS'] = "Logged in as";
|
||||
$content['LN_MENU_MAXVIEW'] = "Maximize View";
|
||||
$content['LN_MENU_NORMALVIEW'] = "Normalize View";
|
||||
$content['LN_MENU_STATISTICS'] = "Statistics";
|
||||
|
||||
// Main Index Site
|
||||
$content['LN_ERROR_INSTALLFILEREMINDER'] = "Atenção! Você ainda NÃO removeu o arquivo 'install.php' do diretório de seu phpLogCon!";
|
||||
|
109
src/statistics.php
Normal file
109
src/statistics.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/*
|
||||
*********************************************************************
|
||||
* phpLogCon - http://www.phplogcon.org
|
||||
* -----------------------------------------------------------------
|
||||
* Details File
|
||||
*
|
||||
* -> Shows Statistic, Charts and more
|
||||
*
|
||||
* All directives are explained within this file
|
||||
*
|
||||
* Copyright (C) 2008 Adiscon GmbH.
|
||||
*
|
||||
* This file is part of phpLogCon.
|
||||
*
|
||||
* PhpLogCon 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.
|
||||
*
|
||||
* PhpLogCon 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 phpLogCon. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* A copy of the GPL can be found in the file "COPYING" in this
|
||||
* distribution
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
// *** Default includes and procedures *** //
|
||||
define('IN_PHPLOGCON', true);
|
||||
$gl_root_path = './';
|
||||
|
||||
// Now include necessary include files!
|
||||
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 LogStream facility
|
||||
include($gl_root_path . 'classes/logstream.class.php');
|
||||
|
||||
InitPhpLogCon();
|
||||
InitSourceConfigs();
|
||||
InitFrontEndDefaults(); // Only in WebFrontEnd
|
||||
InitFilterHelpers(); // Helpers for frontend filtering!
|
||||
// ---
|
||||
|
||||
// --- CONTENT Vars
|
||||
// ---
|
||||
|
||||
// --- BEGIN Custom Code
|
||||
/*if ( isset($content['Sources'][$currentSourceID]) )
|
||||
{
|
||||
// Obtain and get the Config Object
|
||||
$stream_config = $content['Sources'][$currentSourceID]['ObjRef'];
|
||||
|
||||
// Create LogStream Object
|
||||
$stream = $stream_config->LogStreamFactory($stream_config);
|
||||
$res = $stream->Open( $content['AllColumns'], true );
|
||||
if ( $res == SUCCESS )
|
||||
{
|
||||
// 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'];
|
||||
}
|
||||
|
||||
// Close file!
|
||||
$stream->Close();
|
||||
}
|
||||
*/
|
||||
|
||||
// ---
|
||||
|
||||
// --- BEGIN CREATE TITLE
|
||||
$content['TITLE'] = InitPageTitle();
|
||||
|
||||
// Append custom title part!
|
||||
$content['TITLE'] .= " :: " . $content['LN_MENU_STATISTICS'];
|
||||
// --- END CREATE TITLE
|
||||
|
||||
// --- Parsen and Output
|
||||
InitTemplateParser();
|
||||
$page -> parser($content, "statistics.html");
|
||||
$page -> output();
|
||||
// ---
|
||||
|
||||
|
||||
?>
|
@ -1,13 +1,14 @@
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="2">
|
||||
<tr>
|
||||
<td class="topmenu1begin" nowrap align="center" width="16"><img align="left" src="{MENU_BULLET_GREEN}" width="16" height="16" vspace="0"></td>
|
||||
<td class="topmenu1" nowrap align="center" width="100"><a class="topmenu1_link" href="{BASEPATH}search.php" target="_top"><img align="left" src="{MENU_SEARCH}" width="16" height="16" vspace="0">{LN_MENU_SEARCH}</a></td>
|
||||
<td class="topmenu1" nowrap align="center" width="75"><a class="topmenu1_link" href="{BASEPATH}search.php" target="_top"><img align="left" src="{MENU_SEARCH}" width="16" height="16" vspace="0">{LN_MENU_SEARCH}</a></td>
|
||||
<td class="topmenu1" nowrap align="center" width="100"><a class="topmenu1_link" href="{BASEPATH}index.php?{additional_url}" target="_top"><img align="left" src="{MENU_HOMEPAGE}" width="16" height="16" vspace="0">{LN_MENU_SHOWEVENTS}</a></td>
|
||||
<td class="topmenu1" nowrap align="center" width="90"><a class="topmenu1_link" href="{BASEPATH}statistics.php" target="_top"><img align="left" src="{MENU_CHARTS}" width="16" height="16" vspace="0">{LN_MENU_STATISTICS}</a></td>
|
||||
<!-- <td class="topmenu1" nowrap align="center" width="125"><a class="topmenu1_link" href="" target="_top">Show SysLogTags</a></td>-->
|
||||
<!-- <td class="topmenu1" nowrap align="center" width="100"><a class="topmenu1_link" href="" target="_top">User Options</a></td>-->
|
||||
<!-- <td class="topmenu1" nowrap align="center" width="125"><a class="topmenu1_link" href="" target="_top">Database Options</a></td>-->
|
||||
<!-- <td class="topmenu1" nowrap align="center" width="100"><a class="topmenu1_link" href="?" target="_top">Refresh</a></td>-->
|
||||
<td class="topmenu1" nowrap align="center" width="75"><a class="topmenu1_link" href="http://wiki.rsyslog.com/index.php/PhpLogCon" target="phplogcon_help"><img align="left" src="{MENU_HELP}" width="16" height="16" vspace="0">{LN_MENU_HELP}</a></td>
|
||||
<td class="topmenu1" nowrap align="center" width="60"><a class="topmenu1_link" href="http://wiki.rsyslog.com/index.php/PhpLogCon" target="phplogcon_help"><img align="left" src="{MENU_HELP}" width="16" height="16" vspace="0">{LN_MENU_HELP}</a></td>
|
||||
<td class="topmenu1" nowrap align="center" width="200"><a class="topmenu1_link" href="http://kb.monitorware.com/search.php" target="_blank"><img align="left" src="{MENU_KB}" width="16" height="16" vspace="0">{LN_MENU_SEARCHINKB}</a></td>
|
||||
<!-- IF UserDBEnabled="true" -->
|
||||
<!-- IF SESSION_LOGGEDIN!="true" -->
|
||||
|
37
src/templates/statistics.html
Normal file
37
src/templates/statistics.html
Normal file
@ -0,0 +1,37 @@
|
||||
<!-- INCLUDE include_header.html -->
|
||||
|
||||
<!-- IF ISERROR="true" -->
|
||||
<br><br>
|
||||
<center>
|
||||
<div class="table_with_border_second ErrorMsg" style="width:600px">
|
||||
<div class="PriorityError">{LN_GEN_ERRORDETAILS}</div>
|
||||
<p>{ERROR_MSG}</p>
|
||||
</div>
|
||||
<br><br>
|
||||
</center>
|
||||
<br><br>
|
||||
<!-- ENDIF ISERROR="true" -->
|
||||
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
|
||||
<tr>
|
||||
<td colspan="3" class="title" nowrap><B>{LN_MENU_STATISTICS}</B></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%" valign="top" class="line1">
|
||||
<br><br>
|
||||
|
||||
<table width="400" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
|
||||
<tr><td class="cellmenu1" align="center"><B>{LN_STATS_GRAPH}: {LN_STATS_COUNTBYSOURCE}</B></td></tr>
|
||||
<tr><td class="line2"><img src="{BASEPATH}chartgenerator.php?type=1&byfield=FROMHOST&width=400" width="400"></td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
<br><br>
|
||||
</td>
|
||||
<td width="50%" valign="top" class="line1">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- INCLUDE include_footer.html -->
|
Loading…
x
Reference in New Issue
Block a user