From 8437f42e2cee3d6509f724aa376126d55bb65d9a Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 13 Nov 2009 16:48:33 +0100 Subject: [PATCH] started templates for monilog report --- src/classes/reports/report.class.php | 31 ++++- .../reports/report.eventlog.monilog.class.php | 100 +++++++++------- .../reports/report.eventlog.monilog.pdf | 0 .../report.eventlog.monilog.template.html | 109 ++++++++++++++++++ ...l => report.eventlog.monilog.template.pdf} | 0 src/reportgenerator.php | 15 ++- 6 files changed, 208 insertions(+), 47 deletions(-) delete mode 100644 src/classes/reports/report.eventlog.monilog.pdf create mode 100644 src/classes/reports/report.eventlog.monilog.template.html rename src/classes/reports/{report.eventlog.monilog.html => report.eventlog.monilog.template.pdf} (100%) diff --git a/src/classes/reports/report.class.php b/src/classes/reports/report.class.php index 267b889..bca723c 100644 --- a/src/classes/reports/report.class.php +++ b/src/classes/reports/report.class.php @@ -196,7 +196,7 @@ abstract class Report { $this->_outputFormat = $newOutputType; // 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 */ @@ -284,6 +311,8 @@ abstract class Report { */ public function InitFromSavedReport( $mySavedReport ) { + global $content; + // Copy settings from saved report! $this->SetSourceID( $mySavedReport["sourceid"] ); $this->SetCustomTitle( $mySavedReport["customTitle"] ); diff --git a/src/classes/reports/report.eventlog.monilog.class.php b/src/classes/reports/report.eventlog.monilog.class.php index 24b7e18..b30612b 100644 --- a/src/classes/reports/report.eventlog.monilog.class.php +++ b/src/classes/reports/report.eventlog.monilog.class.php @@ -103,39 +103,50 @@ class Report_monilog extends Report { // Verify Datasource first! if ( $this->verifyDataSource() == SUCCESS ) { - // Test opening the stream -// $res = $this->_streamObj->Open( $this->_arrProperties, true ); -// if ( $res == SUCCESS ) + // Get Settings and set to global content variable + $content["report_title"] = $this->GetCustomTitle(); + $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 - // 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 ) { - 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 - $content["report_computers"] = $this->_streamObj->ConsolidateItemListByField( SYSLOG_HOST, $this->_maxHosts, SYSLOG_HOST, SORTING_ORDER_DESC ); + // Prepent Item with totalevents count + $totalItem['DisplayName'] = "Total Events"; + $totalItem['bgcolor'] = "999999"; + $totalItem['ItemCount'] = $iTotalEvents; - // 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); - - // --- + // Prepent to array + array_unshift( $content["report_summary"], $totalItem ); } + // 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! @@ -210,34 +221,41 @@ class Report_monilog extends Report { // Check if Event from host is in our hosts array 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 $strChecksum = crc32( $logArray[SYSLOG_MESSAGE] ); // 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 - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['ItemCount']++; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['ItemCount']++; // Set FirstEvent date if necessary! - if ( $logArray[SYSLOG_DATE] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['FirstEvent_Date'] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; + if ( $logArray[SYSLOG_DATE] < $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; // Set LastEvent date if necessary! - if ( $logArray[SYSLOG_DATE] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['LastEvent_date'] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE]; + if ( $logArray[SYSLOG_DATE] > $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_date'] ) + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE]; } else { // Set Basic data entries - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $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] ][ $strChecksum ][SYSLOG_EVENT_SOURCE] = $logArray[SYSLOG_EVENT_SOURCE]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_SEVERITY] = $logArray[SYSLOG_SEVERITY]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ][SYSLOG_EVENT_ID] = $logArray[SYSLOG_EVENT_ID]; + $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 - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $strChecksum ]['ItemCount'] = 1; - $content["report_consdata"][ $logArray[SYSLOG_HOST] ][ $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 ]['ItemCount'] = 1; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_date'] = $logArray[SYSLOG_DATE]; //GetFormatedDate } @@ -252,15 +270,15 @@ class Report_monilog extends Report { foreach( $content["report_consdata"] as &$tmpConsolidatedComputer ) { // First use callback function to sort array - uasort($tmpConsolidatedComputer, "MultiSortArrayByItemCountDesc"); + uasort($tmpConsolidatedComputer['cons_events'], "MultiSortArrayByItemCountDesc"); // Remove entries according to _maxEventsPerHost - if ( count($tmpConsolidatedComputer) > $this->_maxEventsPerHost ) + if ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost ) { do { - array_pop($tmpConsolidatedComputer); - } while ( count($tmpConsolidatedComputer) > $this->_maxEventsPerHost ); + array_pop($tmpConsolidatedComputer['cons_events']); + } while ( count($tmpConsolidatedComputer['cons_events']) > $this->_maxEventsPerHost ); } } diff --git a/src/classes/reports/report.eventlog.monilog.pdf b/src/classes/reports/report.eventlog.monilog.pdf deleted file mode 100644 index e69de29..0000000 diff --git a/src/classes/reports/report.eventlog.monilog.template.html b/src/classes/reports/report.eventlog.monilog.template.html new file mode 100644 index 0000000..73e8bbc --- /dev/null +++ b/src/classes/reports/report.eventlog.monilog.template.html @@ -0,0 +1,109 @@ + + + + {report_title} + + + + + + + + + + + + + + + + +
{report_title}
{report_comment}
+ +

+ + + + + + + + + +
{report_summary}
+ + + + + + + + + + + +
{report_event_summary}
{DisplayName}{ItemCount}
+ + + + + + + + +
{report_computer_summary}
+ + {FROMHOST}({ItemCount}), + +
+ +
+ + + + + + +
{report_consolidation}
+ + + +

+

{FROMHOST}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{report_number}{report_firstevent}{report_lastevent}{report_process}{report_severity}{report_eventid}{report_description}{report_count}
{ZAEHLER}{FirstEvent_Date}{LastEvent_date}{sourceproc}{syslogseverity}{id}{msg}{ItemCount}{ItemCount}
+ + + + + \ No newline at end of file diff --git a/src/classes/reports/report.eventlog.monilog.html b/src/classes/reports/report.eventlog.monilog.template.pdf similarity index 100% rename from src/classes/reports/report.eventlog.monilog.html rename to src/classes/reports/report.eventlog.monilog.template.pdf diff --git a/src/reportgenerator.php b/src/reportgenerator.php index 4812450..c1ee758 100644 --- a/src/reportgenerator.php +++ b/src/reportgenerator.php @@ -203,14 +203,19 @@ if ( !$content['error_occured'] ) } else { - // Perform report output - InitTemplateParser(); - echo $myReportObj->_baseFileName; - exit; + // --- Perform report output - $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(); + // --- } } }