mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
-splitted property constants, so we can clearly assign them to the logstream
facility. -Added config Init function, which will read and init Source Configs. -Changed index.php so it displayes from the current selected Source
This commit is contained in:
parent
4dc2dfb21c
commit
79aeab308e
@ -154,6 +154,7 @@ class LogStreamDisk extends LogStream {
|
||||
if (($pos = strpos($this->_buffer, "\n", $this->_p_buffer)) !== false) {
|
||||
$uID = $this->_currentStartPos;
|
||||
$logLine = $line . substr($this->_buffer, $this->_p_buffer, $pos - $this->_p_buffer);
|
||||
$arrProperitesOut[SYSLOG_DATE] = '';
|
||||
$arrProperitesOut[SYSLOG_FACILITY] = '';
|
||||
$arrProperitesOut[SYSLOG_FACILITY_TEXT] = '';
|
||||
$arrProperitesOut[SYSLOG_SEVERITY] = '';
|
||||
|
66
include/constants_logstream.php
Normal file
66
include/constants_logstream.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
*********************************************************************
|
||||
* Copyright by Adiscon GmbH | 2008! *
|
||||
* -> www.phplogcon.org <- *
|
||||
* *
|
||||
* Use this script at your own risk! *
|
||||
* ----------------------------------------------------------------- *
|
||||
* Some constants *
|
||||
* *
|
||||
* -> Stuff which has to be static and predefined *
|
||||
* *
|
||||
* All directives are explained within this file *
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
// --- Avoid directly accessing this file!
|
||||
if ( !defined('IN_PHPLOGCON') )
|
||||
{
|
||||
die('Hacking attempt');
|
||||
exit;
|
||||
}
|
||||
// ---
|
||||
|
||||
// --- Some custom defines
|
||||
|
||||
// Properties we need from the stream class
|
||||
define('SYSLOG_DATE', 'timereported');
|
||||
define('SYSLOG_FACILITY', 'syslogfacility');
|
||||
define('SYSLOG_FACILITY_TEXT', 'syslogfacility-text');
|
||||
define('SYSLOG_SEVERITY', 'syslogseverity');
|
||||
define('SYSLOG_SEVERITY_TEXT','syslogseverity-text');
|
||||
define('SYSLOG_HOST', 'FROMHOST');
|
||||
define('SYSLOG_SYSLOGTAG', 'syslogtag');
|
||||
define('SYSLOG_MESSAGE', 'msg');
|
||||
define('SYSLOG_MESSAGETRUNSCATED', 'msgtrunscated');
|
||||
define('SYSLOG_MESSAGETYPE', 'IUT');
|
||||
|
||||
// MonitorWare InfoUnit Defines
|
||||
define('IUT_Unknown', '0');
|
||||
define('IUT_Syslog', '1');
|
||||
define('IUT_Heartbeat', '2');
|
||||
define('IUT_NT_EventReport', '3');
|
||||
define('IUT_SNMP_Trap', '4');
|
||||
define('IUT_File_Monitor', '5');
|
||||
define('IUT_PingProbe', '8');
|
||||
define('IUT_Port_Probe', '9');
|
||||
define('IUT_NTService_Monitor', '10');
|
||||
define('IUT_DiskSpace_Monitor', '11');
|
||||
define('IUT_DB_Monitor', '12');
|
||||
define('IUT_Serial_Monitor', '13');
|
||||
define('IUT_CPU_Monitor', '14');
|
||||
define('IUT_AliveMonRequest', '16');
|
||||
define('IUT_SMTPProbe', '17');
|
||||
define('IUT_FTPProbe', '18');
|
||||
define('IUT_HTTPProbe', '19');
|
||||
define('IUT_POP3Probe', '20');
|
||||
define('IUT_IMAPProbe', '21');
|
||||
define('IUT_NNTPProbe', '22');
|
||||
define('IUT_WEVTMONV2', '23');
|
||||
define('IUT_SMTPLISTENER', '24');
|
||||
define('IUT_AliveMonECHO', '1999998');
|
||||
define('IUT_MIAP_Receiver', '1999999');
|
||||
|
||||
// ---
|
||||
?>
|
@ -24,10 +24,12 @@ if ( !defined('IN_PHPLOGCON') )
|
||||
|
||||
// --- Basic Includes
|
||||
include($gl_root_path . 'include/constants_general.php');
|
||||
include($gl_root_path . 'config.php');
|
||||
|
||||
include($gl_root_path . 'classes/class_template.php');
|
||||
include($gl_root_path . 'include/functions_themes.php');
|
||||
include($gl_root_path . 'include/functions_db.php');
|
||||
include($gl_root_path . 'classes/class_template.php');
|
||||
include($gl_root_path . 'config.php');
|
||||
include($gl_root_path . 'include/functions_config.php');
|
||||
// ---
|
||||
|
||||
// --- Define Basic vars
|
||||
|
87
include/functions_config.php
Normal file
87
include/functions_config.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*
|
||||
*********************************************************************
|
||||
* Copyright by Adiscon GmbH | 2008! *
|
||||
* -> www.phplogcon.org <- *
|
||||
* *
|
||||
* Use this script at your own risk! *
|
||||
* ----------------------------------------------------------------- *
|
||||
* Maintain and read Source Configurations *
|
||||
* *
|
||||
* -> Configuration need variables for the Database connection *
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
// --- Avoid directly accessing this file!
|
||||
if ( !defined('IN_PHPLOGCON') )
|
||||
{
|
||||
die('Hacking attempt');
|
||||
exit;
|
||||
}
|
||||
// ---
|
||||
|
||||
require_once('classes/logstreamconfig.class.php');
|
||||
require_once('classes/logstreamconfigdisk.class.php');
|
||||
|
||||
function InitSourceConfigs()
|
||||
{
|
||||
global $CFG, $Sources, $currentSourceID;
|
||||
|
||||
// Init Source Configs!
|
||||
if ( isset($CFG['Sources']) )
|
||||
{
|
||||
$iCount = count($CFG['Sources']);
|
||||
for ( $i = 0; $i< $iCount; $i++ )
|
||||
{
|
||||
if ( isset($CFG['Sources'][$i]['SourceType']) )
|
||||
{
|
||||
// Set Array Index, TODO: Check for invalid characters!
|
||||
$iSourceID = $CFG['Sources'][$i]['ID'];
|
||||
if ( !isset($Sources[$iSourceID]) )
|
||||
{
|
||||
// Copy general properties
|
||||
$Sources[$iSourceID]['Name'] = $CFG['Sources'][$i]['Name'];
|
||||
$Sources[$iSourceID]['SourceType'] = $CFG['Sources'][$i]['SourceType'];
|
||||
|
||||
// Create Config instance!
|
||||
if ( $CFG['Sources'][$i]['SourceType'] == SOURCE_DISK )
|
||||
{
|
||||
$Sources[$iSourceID]['ObjRef'] = new LogStreamConfigDisk();
|
||||
$Sources[$iSourceID]['ObjRef']->FileName = $CFG['Sources'][$i]['DiskFile'];
|
||||
}
|
||||
else if ( $CFG['Sources'][$i]['SourceType'] == SOURCE_MYSQLDB )
|
||||
{
|
||||
// TODO!
|
||||
die( "Not supported yet!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// UNKNOWN, remove config entry!
|
||||
unset($Sources[$iSourceID]);
|
||||
|
||||
// TODO: Output CONFIG WARNING
|
||||
}
|
||||
|
||||
// Set default SourceID here!
|
||||
if ( isset($Sources[$iSourceID]) && !isset($currentSourceID) )
|
||||
$currentSourceID = $iSourceID;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: OUTPUT CONFIG WARNING - duplicated ID!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set Source from session if available!
|
||||
if ( isset($_SESSION['currentSourceID']) && isset($Sources[$_SESSION['currentSourceID']]) )
|
||||
$currentSourceID = $_SESSION['currentSourceID'];
|
||||
else
|
||||
{
|
||||
// No Source stored in session, then to so now!
|
||||
$_SESSION['currentSourceID'] = $currentSourceID;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
*********************************************************************
|
||||
* Copyright by Adiscon GmbH | 2008! *
|
||||
* -> www.phplogcon.org <- *
|
||||
* *
|
||||
* Use this script at your own risk! *
|
||||
* ----------------------------------------------------------------- *
|
||||
* Parser functions *
|
||||
* *
|
||||
* All directives are explained within this file *
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
// --- Avoid directly accessing this file!
|
||||
if ( !defined('IN_PHPLOGCON') )
|
||||
{
|
||||
die('Hacking attempt');
|
||||
exit;
|
||||
}
|
||||
// ---
|
||||
|
||||
function ParseSyslogHeader($szLogLine)
|
||||
{
|
||||
// Init values
|
||||
$syslogDate = "Feb 7 17:56:24";
|
||||
$syslogFacility = 16;
|
||||
$syslogFacilityText = "kernel";
|
||||
$syslogSeverity = 5;
|
||||
$syslogSeverityText = "notice";
|
||||
$syslogTag = "syslog";
|
||||
$syslogHost = "localhost";
|
||||
$syslogMsg = $szLogLine;
|
||||
$syslogIUT = IUT_Syslog;
|
||||
|
||||
// Parse from logline!
|
||||
//SAMPLE: Mar 10 14:45:39 debandre syslogd 1.4.1#18: restart.
|
||||
//SAMPLE: Mar 10 14:45:44 debandre anacron[3226]: Job `cron.daily' terminated (mailing output)
|
||||
//'<' % text($pri) & '>' & date2text($datereceived, rfc3339) & $hostname & tolower($msg)
|
||||
|
||||
SYSLOG_DATE => $syslogDate,
|
||||
array ( SYSLOG_FACILITY, SYSLOG_FACILITY_TEXT, SYSLOG_SEVERITY, SYSLOG_SEVERITY_TEXT, SYSLOG_HOST, SYSLOG_SYSLOGTAG, SYSLOG_MESSAGE, SYSLOG_MESSAGETYPE );
|
||||
|
||||
// return results
|
||||
return array (
|
||||
SYSLOG_DATE => $syslogDate,
|
||||
SYSLOG_FACILITY => $syslogFacility,
|
||||
SYSLOG_FACILITY_TEXT => $syslogFacilityText,
|
||||
SYSLOG_SEVERITY => $syslogSeverity,
|
||||
SYSLOG_SEVERITY_TEXT => $syslogSeverityText,
|
||||
SYSLOG_HOST => $syslogHost,
|
||||
SYSLOG_SYSLOGTAG => $syslogTag,
|
||||
SYSLOG_MESSAGE => $syslogMsg,
|
||||
SYSLOG_MESSAGETRUNSCATED => strlen($syslogMsg) > 100 ? substr($syslogMsg, 0, 100 ) . " ..." : $syslogMsg,
|
||||
SYSLOG_MESSAGETYPE => $syslogIUT
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
?>
|
33
index.php
33
index.php
@ -18,10 +18,10 @@
|
||||
define('IN_PHPLOGCON', true);
|
||||
$gl_root_path = './';
|
||||
include($gl_root_path . 'include/functions_common.php');
|
||||
include($gl_root_path . 'include/functions_parser.php');
|
||||
include($gl_root_path . 'include/functions_frontendhelpers.php');
|
||||
|
||||
InitPhpLogCon();
|
||||
InitSourceConfigs();
|
||||
InitFrontEndDefaults(); // Only in WebFrontEnd
|
||||
// *** *** //
|
||||
|
||||
@ -33,27 +33,38 @@ InitFrontEndDefaults(); // Only in WebFrontEnd
|
||||
// ---
|
||||
|
||||
// --- BEGIN Custom Code
|
||||
if ( $CFG['SourceType'] == SOURCE_DISK )
|
||||
if ( isset($Sources[$currentSourceID]) && $Sources[$currentSourceID]['SourceType'] == SOURCE_DISK )
|
||||
{
|
||||
require_once('classes/enums.class.php');
|
||||
require_once('classes/logstream.class.php');
|
||||
require_once('classes/logstreamconfig.class.php');
|
||||
require_once('classes/logstreamconfigdisk.class.php');
|
||||
require_once('classes/logstreamdisk.class.php');
|
||||
require_once('include/constants_errors.php');
|
||||
$stream_config = new LogStreamConfigDisk();
|
||||
$stream_config->FileName = $CFG['DiskFile'];
|
||||
require_once('include/constants_logstream.php');
|
||||
|
||||
|
||||
// Obtain Config Object
|
||||
$stream_config = $Sources[$currentSourceID]['ObjRef'];
|
||||
|
||||
// Create LogStream Object
|
||||
$stream = $stream_config->LogStreamFactory($stream_config);
|
||||
$stream->Open(null, true);
|
||||
$stream->Open( array ( SYSLOG_DATE, SYSLOG_FACILITY, SYSLOG_FACILITY_TEXT, SYSLOG_SEVERITY, SYSLOG_SEVERITY_TEXT, SYSLOG_HOST, SYSLOG_SYSLOGTAG, SYSLOG_MESSAGE, SYSLOG_MESSAGETYPE ), true);
|
||||
$uID = -1;
|
||||
$logLine = '';
|
||||
$counter = 0;
|
||||
|
||||
$stream->SetReadDirection(EnumReadDirection::Backward);
|
||||
// $stream->SetReadDirection(EnumReadDirection::Backward);
|
||||
|
||||
while ($stream->ReadNext($uID, $logLine) == 0 && $counter <= 30)
|
||||
while ($stream->ReadNext($uID, $logArray) == 0 && $counter <= 30)
|
||||
{
|
||||
$content['syslogmessages'][] = ParseSyslogHeader($logLine);
|
||||
// Copy Obtained array
|
||||
$content['syslogmessages'][] = $logArray;
|
||||
|
||||
// Set truncasted message for display
|
||||
if ( isset($logArray[SYSLOG_MESSAGE]) )
|
||||
$content['syslogmessages'][$counter][SYSLOG_MESSAGETRUNSCATED] = strlen($logArray[SYSLOG_MESSAGE]) > 100 ? substr($logArray[SYSLOG_MESSAGE], 0, 100 ) . " ..." : $logArray[SYSLOG_MESSAGE];
|
||||
else
|
||||
$content['syslogmessages'][$counter][SYSLOG_MESSAGETRUNSCATED] = "";
|
||||
|
||||
// Increment Counter
|
||||
$counter++;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user