Enhanced template parser to support IF statements with lower or higher operation

This commit is contained in:
Andre Lorbach 2009-11-16 12:35:17 +01:00
parent 8437f42e2c
commit aa5d9786be
3 changed files with 34 additions and 12 deletions

View File

@ -237,6 +237,29 @@ function template_parser_sub($template, $values)
}
}
if (preg_match_all( '<!-- IF ([a-zA-Z0-9_]+)([!<>]+)([^"]*) -->', $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( "<!-- IF $blockname$cmp$blockvalue -->", "", $template );
$template = str_replace( "<!-- ENDIF $blockname$cmp$blockvalue -->", "", $template );
}
else if ($blockend = strpos( $template, "<!-- ENDIF $blockname$cmp$blockvalue -->"))
{
$blockbeg = strpos($template, "<!-- IF $blockname$cmp$blockvalue -->");
$template = substr($template, 0, $blockbeg) . substr($template, $blockend + 18 + strlen($blockname) + strlen($blockvalue) + strlen($cmp));
}
}
}
return $template;

View File

@ -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
}

View File

@ -86,17 +86,17 @@
<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">{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 -->
<!-- IF ItemCount>10 -->
<td class="lineColouredWhite" valign="top" align="right" bgcolor="red"><b>{ItemCount}</b></td>
<!-- ENDIF ItemCount > 10 -->
<!-- IF ItemCount < 10 -->
<!-- ENDIF ItemCount>10 -->
<!-- IF ItemCount<11 -->
<td class="lineColouredWhite" valign="top" align="right" bgcolor="#AAAAAA"><b>{ItemCount}</b></td>
<!-- ENDIF ItemCount < 10 -->
<!-- ENDIF ItemCount<11 -->
</tr>