started templates for monilog report

This commit is contained in:
Andre Lorbach 2009-11-13 16:48:33 +01:00
parent 91a61d8e76
commit 8437f42e2c
6 changed files with 208 additions and 47 deletions

View File

@ -196,7 +196,7 @@ abstract class Report {
$this->_outputFormat = $newOutputType; $this->_outputFormat = $newOutputType;
// Set Filebasename // Set Filebasename
$this->_baseFileName = $this->_reportID . ".template." . $this->_outputFormat; $this->_baseFileName = $this->_reportFileBasicName . ".template." . $this->_outputFormat;
} }
/* /*
@ -271,6 +271,33 @@ abstract class Report {
} }
} }
/*
* Helper function to return the BaseFileName
*/
public function GetBaseFileName()
{
// return Filebasename
return $this->_baseFileName;
}
/*
* Helper function to return the CustomTitle
*/
public function GetCustomTitle()
{
// return Filebasename
return $this->_customTitle;
}
/*
* Helper function to return the CustomComment
*/
public function GetCustomComment()
{
// return Filebasename
return $this->_customComment;
}
/* /*
* Helper function to trigger initialisation * Helper function to trigger initialisation
*/ */
@ -284,6 +311,8 @@ abstract class Report {
*/ */
public function InitFromSavedReport( $mySavedReport ) public function InitFromSavedReport( $mySavedReport )
{ {
global $content;
// Copy settings from saved report! // Copy settings from saved report!
$this->SetSourceID( $mySavedReport["sourceid"] ); $this->SetSourceID( $mySavedReport["sourceid"] );
$this->SetCustomTitle( $mySavedReport["customTitle"] ); $this->SetCustomTitle( $mySavedReport["customTitle"] );

View File

@ -103,39 +103,50 @@ class Report_monilog extends Report {
// Verify Datasource first! // Verify Datasource first!
if ( $this->verifyDataSource() == SUCCESS ) if ( $this->verifyDataSource() == SUCCESS )
{ {
// Test opening the stream // Get Settings and set to global content variable
// $res = $this->_streamObj->Open( $this->_arrProperties, true ); $content["report_title"] = $this->GetCustomTitle();
// if ( $res == SUCCESS ) $content["report_comment"] = $this->GetCustomComment();
// --- Report logic starts here
// Step 1: Gather Summaries
// Obtain data from the logstream!
$content["report_summary"] = $this->_streamObj->ConsolidateDataByField( SYSLOG_SEVERITY, 0, SYSLOG_SEVERITY, SORTING_ORDER_DESC, null, false );
// If data is valid, we have an array!
if ( is_array($content["report_summary"]) && count($content["report_summary"]) > 0 )
{ {
// --- Report logic starts here // Count Total Events
$iTotalEvents = 0;
// Step 1: Gather Summaries foreach ($content["report_summary"] as &$tmpReportData )
// Obtain data from the logstream!
$content["report_summary"] = $this->_streamObj->ConsolidateDataByField( SYSLOG_SEVERITY, 0, SYSLOG_SEVERITY, SORTING_ORDER_DESC, null, false );
// If data is valid, we have an array!
if ( is_array($content["report_summary"]) && count($content["report_summary"]) > 0 )
{ {
foreach ($content["report_summary"] as &$tmpReportData ) $tmpReportData['DisplayName'] = GetSeverityDisplayName( $tmpReportData[SYSLOG_SEVERITY] );
{ $tmpReportData['bgcolor'] = $severity_colors[ $tmpReportData[SYSLOG_SEVERITY] ];
$tmpReportData['DisplayName'] = GetSeverityDisplayName( $tmpReportData[SYSLOG_SEVERITY] );
$tmpReportData['bgcolor'] = $severity_colors[ $tmpReportData[SYSLOG_SEVERITY] ]; $iTotalEvents += $tmpReportData['ItemCount'];
}
} }
// Get List of hosts // Prepent Item with totalevents count
$content["report_computers"] = $this->_streamObj->ConsolidateItemListByField( SYSLOG_HOST, $this->_maxHosts, SYSLOG_HOST, SORTING_ORDER_DESC ); $totalItem['DisplayName'] = "Total Events";
$totalItem['bgcolor'] = "999999";
$totalItem['ItemCount'] = $iTotalEvents;
// Create plain hosts list for Consolidate function // Prepent to array
foreach ( $content["report_computers"] as $tmpComputer ) array_unshift( $content["report_summary"], $totalItem );
$arrHosts[] = $tmpComputer[SYSLOG_HOST];
// This function will consolidate the Events based per Host!
$this->ConsolidateEventsPerHost($arrHosts);
// ---
} }
// Get List of hosts
$content["report_computers"] = $this->_streamObj->ConsolidateItemListByField( SYSLOG_HOST, $this->_maxHosts, SYSLOG_HOST, SORTING_ORDER_DESC );
// Create plain hosts list for Consolidate function
foreach ( $content["report_computers"] as $tmpComputer )
$arrHosts[] = $tmpComputer[SYSLOG_HOST];
// This function will consolidate the Events based per Host!
$this->ConsolidateEventsPerHost($arrHosts);
// ---
} }
// Return success! // Return success!
@ -210,34 +221,41 @@ class Report_monilog extends Report {
// Check if Event from host is in our hosts array // Check if Event from host is in our hosts array
if ( in_array($logArray[SYSLOG_HOST], $arrHosts) ) if ( in_array($logArray[SYSLOG_HOST], $arrHosts) )
{ {
// Set Host Item Basics if not set yet
if ( !isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST]) )
{
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][SYSLOG_HOST] = $logArray[SYSLOG_HOST];
}
// Calc crc32 from message, we use this as index // Calc crc32 from message, we use this as index
$strChecksum = crc32( $logArray[SYSLOG_MESSAGE] ); $strChecksum = crc32( $logArray[SYSLOG_MESSAGE] );
// Check if entry exists in result array // Check if entry exists in result array
if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]) ) if ( isset($content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]) )
{ {
// Increment counter and set First/Last Event date // Increment counter and set First/Last Event date
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['ItemCount']++; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['ItemCount']++;
// Set FirstEvent date if necessary! // Set FirstEvent date if necessary!
if ( $logArray[SYSLOG_DATE] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['FirstEvent_Date'] ) if ( $logArray[SYSLOG_DATE] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] )
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE];
// Set LastEvent date if necessary! // Set LastEvent date if necessary!
if ( $logArray[SYSLOG_DATE] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['LastEvent_date'] ) if ( $logArray[SYSLOG_DATE] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_date'] )
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE];
} }
else else
{ {
// Set Basic data entries // Set Basic data entries
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY];
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ][SYSLOG_EVENT_ID] = $logArray[SYSLOG_EVENT_ID]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_EVENT_ID] = $logArray[SYSLOG_EVENT_ID];
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ][SYSLOG_EVENT_SOURCE] = $logArray[SYSLOG_EVENT_SOURCE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_EVENT_SOURCE] = $logArray[SYSLOG_EVENT_SOURCE];
$content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_MESSAGE] = $logArray[SYSLOG_MESSAGE];
// Set Counter and First/Last Event date // Set Counter and First/Last Event date
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['ItemCount'] = 1; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['ItemCount'] = 1;
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE];
$content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE]; $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE];
//GetFormatedDate //GetFormatedDate
} }
@ -252,15 +270,15 @@ class Report_monilog extends Report {
foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) foreach( $content["report_consdata"] as &$tmpConsolidatedComputer )
{ {
// First use callback function to sort array // First use callback function to sort array
uasort($tmpConsolidatedComputer, "MultiSortArrayByItemCountDesc"); uasort($tmpConsolidatedComputer['cons_events'], "MultiSortArrayByItemCountDesc");
// Remove entries according to _maxEventsPerHost // Remove entries according to _maxEventsPerHost
if ( count($tmpConsolidatedComputer) > $this->_maxEventsPerHost ) if ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost )
{ {
do do
{ {
array_pop($tmpConsolidatedComputer); array_pop($tmpConsolidatedComputer['cons_events']);
} while ( count($tmpConsolidatedComputer) > $this->_maxEventsPerHost ); } while ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost );
} }
} }

View File

@ -0,0 +1,109 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>{report_title}</title>
<link rel="stylesheet" href="{BASEPATH}css/defaults.css" type="text/css">
<link rel="stylesheet" href="{BASEPATH}themes/{user_theme}/main.css" type="text/css">
<link rel="stylesheet" href="{BASEPATH}css/menu.css" type="text/css">
</head>
<body TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
<tr>
<td class="title" width="100%" nowrap><B>{report_title}</B></td>
</td>
</tr>
<tr>
<td class="titleSecond" width="100%" align="left">{report_comment}</td>
</tr>
</table>
<br/><br/>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
<tr>
<td class="title" width="100%" nowrap><B>{report_summary}</B></td>
</td>
</tr>
<tr>
<td class="tableBackground" width="100%" align="left">
<table width="200" cellpadding="0" cellspacing="1" border="0" align="left" class="with_border_alternate">
<tr>
<td class="cellmenu1" colspan="2" align="center">{report_event_summary}</td>
</tr>
<!-- BEGIN report_summary -->
<tr>
<td class="cellmenu2">{DisplayName}</td>
<td class="lineColouredWhite" bgcolor="{bgcolor}" align="right"><b>{ItemCount}</b></td>
</tr>
<!-- END report_summary -->
</table>
<table width="600" cellpadding="0" cellspacing="1" border="0" align="right" class="with_border_alternate">
<tr>
<td class="cellmenu1" colspan="2" align="center">{report_computer_summary}</td>
</tr>
<tr>
<td class="line1">
<!-- BEGIN report_computers -->
<a href="#{FROMHOST}">{FROMHOST}</a>({ItemCount}),
<!-- END report_computers -->
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="with_border">
<tr>
<td class="title" width="100%" nowrap><B>{report_consolidation}</B></td>
</td>
</tr>
</table>
<!-- BEGIN report_consdata -->
<br/><br/>
<h3><a name="{FROMHOST}">{FROMHOST}</a></h3>
<table width="100%" cellpadding="0" cellspacing="1" border="0" align="center" class="with_border_alternate">
<tr>
<td class="cellmenu1" align="center" width="50">{report_number}</td>
<td class="cellmenu1" align="center" width="100">{report_firstevent}</td>
<td class="cellmenu1" align="center" width="100">{report_lastevent}</td>
<td class="cellmenu1" align="center" width="150">{report_process}</td>
<td class="cellmenu1" align="center" width="100">{report_severity}</td>
<td class="cellmenu1" align="center" width="80">{report_eventid}</td>
<td class="cellmenu1" align="center" width="100%">{report_description}</td>
<td class="cellmenu1" align="center" width="50">{report_count}</td>
</tr>
<!-- BEGIN cons_events -->
<tr>
<td class="line1" valign="top">{ZAEHLER}</td>
<td class="line1" valign="top">{FirstEvent_Date}</td>
<td class="line1" valign="top">{LastEvent_date}</td>
<td class="line1" valign="top">{sourceproc}</td>
<td class="line1" valign="top">{syslogseverity}</td>
<td class="line1" valign="top">{id}</td>
<td class="line1" valign="top">{msg}</td>
<!-- IF ItemCount > 10 -->
<td class="lineColouredWhite" valign="top" align="right" bgcolor="red"><b>{ItemCount}</b></td>
<!-- ENDIF ItemCount > 10 -->
<!-- IF ItemCount < 10 -->
<td class="lineColouredWhite" valign="top" align="right" bgcolor="#AAAAAA"><b>{ItemCount}</b></td>
<!-- ENDIF ItemCount < 10 -->
</tr>
<!-- END cons_events -->
</table>
<!-- END report_consdata -->
</body>
</html>

View File

@ -203,14 +203,19 @@ if ( !$content['error_occured'] )
} }
else else
{ {
// Perform report output // --- Perform report output
InitTemplateParser();
echo $myReportObj->_baseFileName;
exit;
$page -> parser($content, "reportgenerator.html"); // Init template Parser
$page = new Template();
$page -> set_path ( $gl_root_path . 'classes/reports/' );
// Parse template
$page -> parser($content, $myReportObj->GetBaseFileName());
// Output to browser
$page -> output(); $page -> output();
// ---
} }
} }
} }