From aa5d9786bee954c62d5db63b5f21696d59115fe3 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Mon, 16 Nov 2009 12:35:17 +0100 Subject: [PATCH] Enhanced template parser to support IF statements with lower or higher operation --- src/classes/class_template.php | 23 +++++++++++++++++++ .../reports/report.eventlog.monilog.class.php | 13 +++++------ .../report.eventlog.monilog.template.html | 10 ++++---- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/classes/class_template.php b/src/classes/class_template.php index e7b4bcf..ead6d7c 100644 --- a/src/classes/class_template.php +++ b/src/classes/class_template.php @@ -237,6 +237,29 @@ function template_parser_sub($template, $values) } } + if (preg_match_all( '', $template, $matches, PREG_SET_ORDER) ) + { +// echo $matches[0][1]; +// echo $matches[0][2]; +// echo $matches[0][3]; +// exit; + + foreach ($matches as $block) { + $blockname = $block[1]; + $cmp = $block[2]; + $blockvalue = $block[3]; + if ( ($cmp == '>' && @$values[$blockname] > $blockvalue) || ($cmp == '<' && @$values[$blockname] < $blockvalue) ) + { + $template = str_replace( "", "", $template ); + $template = str_replace( "", "", $template ); + } + else if ($blockend = strpos( $template, "")) + { + $blockbeg = strpos($template, ""); + $template = substr($template, 0, $blockbeg) . substr($template, $blockend + 18 + strlen($blockname) + strlen($blockvalue) + strlen($cmp)); + } + } + } return $template; diff --git a/src/classes/reports/report.eventlog.monilog.class.php b/src/classes/reports/report.eventlog.monilog.class.php index b30612b..201ce53 100644 --- a/src/classes/reports/report.eventlog.monilog.class.php +++ b/src/classes/reports/report.eventlog.monilog.class.php @@ -145,7 +145,6 @@ class Report_monilog extends Report { // This function will consolidate the Events based per Host! $this->ConsolidateEventsPerHost($arrHosts); - // --- } @@ -237,12 +236,12 @@ class Report_monilog extends Report { $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] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] ) - $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE]; + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] < $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][EVTIME_TIMESTAMP]; // Set LastEvent date if necessary! - 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]; + if ( $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP] > $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][EVTIME_TIMESTAMP]; } else { @@ -254,8 +253,8 @@ class Report_monilog extends Report { // Set Counter and First/Last Event 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]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['FirstEvent_Date'] = $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP]; + $content["report_consdata"][ $logArray[SYSLOG_HOST] ]['cons_events'][ $strChecksum ]['LastEvent_Date'] = $logArray[SYSLOG_DATE][EVTIME_TIMESTAMP]; //GetFormatedDate } diff --git a/src/classes/reports/report.eventlog.monilog.template.html b/src/classes/reports/report.eventlog.monilog.template.html index 73e8bbc..6d0c30d 100644 --- a/src/classes/reports/report.eventlog.monilog.template.html +++ b/src/classes/reports/report.eventlog.monilog.template.html @@ -86,17 +86,17 @@ {ZAEHLER} {FirstEvent_Date} - {LastEvent_date} + {LastEvent_Date} {sourceproc} {syslogseverity} {id} {msg} - + {ItemCount} - - + + {ItemCount} - +