Implemented Customfilters in report class and admin panel, but not all finished yet

This commit is contained in:
Andre Lorbach 2009-12-02 16:27:46 +01:00
parent 0c72fe4de3
commit 1d5e00a104
9 changed files with 323 additions and 152 deletions

View File

@ -295,7 +295,10 @@ if ( isset($_GET['op']) )
$content['customTitle'] = $myReport['DisplayName'];
$content['customComment'] = "";
$content['filterString'] = "";
$content['customFilters'] = "";
// Init Custom Filters
InitCustomFilterDefinitions($myReport, "");
// $content['customFilters'] = "";
// Copy Sources array for further modifications
global $currentSourceID;
@ -368,7 +371,10 @@ if ( isset($_GET['op']) )
$content['customTitle'] = $mySavedReport['customTitle'];
$content['customComment'] = $mySavedReport['customComment'];
$content['filterString'] = $mySavedReport['filterString'];
$content['customFilters'] = $mySavedReport['customFilters'];
// Init Custom Filters
InitCustomFilterDefinitions($myReport, $mySavedReport['customFilters']);
// $content['customFilters'] = $mySavedReport['customFilters'];
// Copy Sources array for further modifications
$content['SOURCES'] = $content['Sources'];
@ -1027,4 +1033,49 @@ $page -> parser($content, "admin/admin_reports.html");
$page -> output();
// ---
// --- BEGIN Helper functions
function InitCustomFilterDefinitions($myReport, $CustomFilterValues)
{
global $content;
// Get Objectreference to report
$myReportObj = $myReport["ObjRef"];
// Get Array of Custom filter Defs
$customFilterDefs = $myReportObj->GetCustomFiltersDefs();
// Include Custom language file if available
$myReportObj->InitReportLanguageFile( $myReportObj->GetReportIncludePath() );
// Loop through filters
$i = 0; // Help counter!
foreach( $customFilterDefs as $filterID => $tmpCustomFilter )
{
// TODO Check if value is available in $CustomFilterValues
$szDefaultValue = $tmpCustomFilter['DefaultValue'];
// TODO Check MIN and MAX value!
// --- Set CSS Class
if ( $i % 2 == 0 )
$szColcssclass = "line1";
else
$szColcssclass = "line2";
$i++;
// ---
$content['CUSTOMFILTERS'][] = array (
'fieldname' => $filterID,
'fieldcaption' => $content[ $tmpCustomFilter['DisplayLangID'] ],
'fielddescription' => $content[ $tmpCustomFilter['DescriptLangID'] ],
'filtertype' => $tmpCustomFilter['filtertype'],
'fieldvalue' => $szDefaultValue,
'colcssclass' => $szColcssclass,
);
}
}
// --- END Helper functions
?>

View File

@ -109,9 +109,9 @@ class Template {
$this->vars = $vars;
if (!isset($this->template)) {
$fname = $this->path . $this->filename . $this->extension;
$this->template = load_file($fname);
$this->template = $this->load_file($fname);
}
$this->page = template_parser( $this->template, $this->vars, $this->path, $this->extension );
$this->page = $this->template_parser( $this->template, $this->vars, $this->path, $this->extension );
}
@ -133,135 +133,168 @@ class Template {
}
}
}
function load_file($fname)
{
if (@is_file($fname))
return join('', file($fname));
else
// Moved into Class
function load_file($fname)
{
// BEGIN DELTA MOD
DieWithErrorMsg( "Could not find the template <B>".$fname."</B>");
// END DELTA MOD
}
}
function template_parser($template, $values, $path = '', $ext = '')
{
while (preg_match("<!-- INCLUDE ([^\>]+) -->", $template, $matches))
$template = str_replace( "<!-- INCLUDE ".$matches[1]." -->", load_file( $path . $matches[1] . $ext), $template );
$template = template_parser_sub($template, $values);
$template = str_replace("\t", " ", $template);
$template = preg_replace("/ +/", " ", $template);
return $template;
}
function template_parser_sub($template, $values)
{
if (is_array($values))
{
foreach ($values as $k => $v)
if (@is_file($fname))
return join('', file($fname));
else
{
if (is_array($v))
// BEGIN DELTA MOD
DieWithErrorMsg( "Could not find the template <B>".$fname."</B>");
// END DELTA MOD
}
}
function template_parser($template, $values, $path = '', $ext = '')
{
while (preg_match("<!-- INCLUDE ([^\>]+) -->", $template, $matches))
$template = str_replace( "<!-- INCLUDE ".$matches[1]." -->", $this->load_file( $path . $matches[1] . $ext), $template );
$template = $this->template_parser_sub($template, $values);
$template = str_replace("\t", " ", $template);
$template = preg_replace("/ +/", " ", $template);
return $template;
}
function template_parser_sub($template, $values)
{
if (is_array($values))
{
foreach ($values as $k => $v)
{
$len = strlen($k);
$lp = strpos($template, "<!-- BEGIN $k -->");
if (is_int($lp))
if (is_array($v))
{
if ($rp = strpos($template, "<!-- END $k -->"))
$len = strlen($k);
$lp = strpos($template, "<!-- BEGIN $k -->");
if (is_int($lp))
{
$page = substr($template, 0, $lp);
$iter = substr($template, $lp + 15 + $len, $rp - $lp - $len - 15);
$rowcnt = 0;
$zaehler = 1;
foreach ($v as $subval)
if ($rp = strpos($template, "<!-- END $k -->"))
{
$subval['COUNTER'] = $rowcnt%2;
$subval['ODDROW'] = $rowcnt%2;
$subval['ROWCNT'] = $rowcnt++;
$subval['ZAEHLER'] = $zaehler++;
$page .= template_parser_sub($iter, $subval);
$page = substr($template, 0, $lp);
$iter = substr($template, $lp + 15 + $len, $rp - $lp - $len - 15);
$rowcnt = 0;
$zaehler = 1;
foreach ($v as $subval)
{
$subval['COUNTER'] = $rowcnt%2;
$subval['ODDROW'] = $rowcnt%2;
$subval['ROWCNT'] = $rowcnt++;
$subval['ZAEHLER'] = $zaehler++;
$page .= $this->template_parser_sub($iter, $subval);
}
$template = $page . substr($template, $rp + 13 + $len);
}
$template = $page . substr($template, $rp + 13 + $len);
}
}
else
{
// FIXED BY ANDRE | Do not convert OBJECTS into strings!
if ( !is_object($k) && !is_object($v) )
$template = str_replace('{'.$k.'}', "$v", $template);
}
}
}
if (preg_match_all("<!-- BEGIN ([a-zA-Z0-9_]+) -->", $template, $matches))
{
foreach ($matches[1] as $block)
{
if (isset($values[$block]))
{
$template = str_replace("<!-- BEGIN $block -->", "", $template);
$template = str_replace("<!-- END $block -->", "", $template);
}
else if ($blockend = strpos($template, "<!-- END $block -->")) {
$blockbeg = strpos($template, "<!-- BEGIN $block -->");
$template = substr($template, 0, $blockbeg) . substr($template, $blockend + 13 + strlen($block));
}
}
}
// else
if (preg_match_all( '<!-- IF ([a-zA-Z0-9_]+)(!?)="([^"]*)" -->', $template, $matches, PREG_SET_ORDER) )
{
// echo $matches[0][0];
// exit;
foreach ($matches as $block) {
$blockname = $block[1];
$not = $block[2];
$blockvalue = $block[3];
if ((@$values[$blockname] == $blockvalue && !$not) || (@$values[$blockname] != $blockvalue && $not))
{
$template = str_replace( "<!-- IF $blockname$not=\"$blockvalue\" -->", "", $template );
$template = str_replace( "<!-- ENDIF $blockname$not=\"$blockvalue\" -->", "", $template );
}
else if ($blockend = strpos( $template, "<!-- ENDIF $blockname$not=\"$blockvalue\" -->"))
{
$blockbeg = strpos($template, "<!-- IF $blockname$not=\"$blockvalue\" -->");
$template = substr($template, 0, $blockbeg) . substr($template, $blockend + 18 + strlen($blockname) + strlen($blockvalue) + strlen($not));
}
}
}
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];
$blockstrvalue = $block[3];
// If $ get from content variable!
if ( strpos($blockstrvalue, "$") !== false )
{
// Trunscate $
$szVarId = substr( $blockstrvalue, 1 );
if ( isset($this->vars[$szVarId]) )
$blockvalue = intval($this->vars[$szVarId]);
else
$blockvalue = intval($blockstrvalue);
}
else // Plain number value
$blockvalue = intval($blockstrvalue);
if ( isset($values[$blockname]) )
{
//echo "$cmp == '>' && @$values[$blockname] > $blockvalue <br>";
// Perform comparison
if (
($cmp == '>' && @$values[$blockname] > $blockvalue) ||
($cmp == '>=' && @$values[$blockname] >= $blockvalue) ||
($cmp == '<' && @$values[$blockname] < $blockvalue) ||
($cmp == '<=' && @$values[$blockname] <= $blockvalue)
)
{
$template = str_replace( "<!-- IF $blockname$cmp$blockstrvalue -->", "", $template );
$template = str_replace( "<!-- ENDIF $blockname$cmp$blockstrvalue -->", "", $template );
}
else if ($blockend = strpos( $template, "<!-- ENDIF $blockname$cmp$blockstrvalue -->"))
{
$blockbeg = strpos($template, "<!-- IF $blockname$cmp$blockstrvalue -->");
$template = substr($template, 0, $blockbeg) . substr($template, $blockend + 18 + strlen($blockname) + strlen($blockstrvalue) + strlen($cmp));
}
}
}
else
{
// FIXED BY ANDRE | Do not convert OBJECTS into strings!
if ( !is_object($k) && !is_object($v) )
$template = str_replace('{'.$k.'}', "$v", $template);
else
{
$template = str_replace( "<!-- IF $blockname$cmp$blockstrvalue -->", "", $template );
$template = str_replace( "<!-- ENDIF $blockname$cmp$blockstrvalue -->", "", $template );
}
}
}
}
if (preg_match_all("<!-- BEGIN ([a-zA-Z0-9_]+) -->", $template, $matches))
{
foreach ($matches[1] as $block)
{
if (isset($values[$block]))
{
$template = str_replace("<!-- BEGIN $block -->", "", $template);
$template = str_replace("<!-- END $block -->", "", $template);
}
else if ($blockend = strpos($template, "<!-- END $block -->")) {
$blockbeg = strpos($template, "<!-- BEGIN $block -->");
$template = substr($template, 0, $blockbeg) . substr($template, $blockend + 13 + strlen($block));
}
}
}
// else
if (preg_match_all( '<!-- IF ([a-zA-Z0-9_]+)(!?)="([^"]*)" -->', $template, $matches, PREG_SET_ORDER) )
{
// echo $matches[0][0];
// exit;
foreach ($matches as $block) {
$blockname = $block[1];
$not = $block[2];
$blockvalue = $block[3];
if ((@$values[$blockname] == $blockvalue && !$not) || (@$values[$blockname] != $blockvalue && $not))
{
$template = str_replace( "<!-- IF $blockname$not=\"$blockvalue\" -->", "", $template );
$template = str_replace( "<!-- ENDIF $blockname$not=\"$blockvalue\" -->", "", $template );
}
else if ($blockend = strpos( $template, "<!-- ENDIF $blockname$not=\"$blockvalue\" -->"))
{
$blockbeg = strpos($template, "<!-- IF $blockname$not=\"$blockvalue\" -->");
$template = substr($template, 0, $blockbeg) . substr($template, $blockend + 18 + strlen($blockname) + strlen($blockvalue) + strlen($not));
}
}
// return processed template
return $template;
}
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

@ -62,8 +62,9 @@ abstract class Report {
// SavedReport Configuration Properties
protected $_customTitle = "";
protected $_customComment = "";
protected $_filterString = "";
protected $_customFilters = "";
protected $_filterString = ""; // Filterstring like used in the search view
protected $_arrCustomFilters = null; // Array contains list of available custom filters, used for admin interface!
protected $_customFilters = ""; // Xml Filterstring containing values for the custom filters
protected $_outputFormat = REPORT_OUTPUT_HTML; // Default HTML Output
protected $_outputTarget = "";
protected $_scheduleSettings = "";
@ -233,6 +234,9 @@ abstract class Report {
{
// Set new Outputtype
$this->_customFilters = $newAdvancedOptions;
echo "TODO SetCustomFilters";
exit;
}
/*
@ -429,6 +433,14 @@ abstract class Report {
return $this->_reportVersion;
}
/*
* Helper function to return the custom filter definitions
*/
public function GetCustomFiltersDefs()
{
return $this->_arrCustomFilters;
}
/*
* Helper function to trigger initialisation
*/
@ -455,6 +467,26 @@ abstract class Report {
$this->SetScheduleSettings( $mySavedReport["scheduleSettings"] );
}
/*
* Helper function to get the report include path
*/
public function GetReportIncludePath()
{
global $gl_root_path;
return $gl_root_path . 'classes/reports/' . $this->_reportFileBasicName . "/";
}
/*
* Helper function to init custom language strings from report!
*/
public function InitReportLanguageFile($szReportIncludePath)
{
// Include Custom language file if available
IncludeLanguageFile( $szReportIncludePath . $this->_reportFileBasicName . ".lang.en.php" );
}
}
?>

View File

@ -59,16 +59,7 @@ class Report_monilog extends Report {
// Advanced Report Options
private $_maxHosts = 20; // Threshold for maximum hosts to analyse!
private $_maxEventsPerHost = 100; // Threshold for maximum amount of events to analyse per host
/* private $_currentOffset = -1;
private $_currentStartPos = -1;
private $_fp = null;
private $_bEOS = false;
const _BUFFER_length = 8192;
private $_buffer = false;
private $_buffer_length = 0;
private $_p_buffer = -1;
*/
private $_colorThreshold = 10; // Threshold for coloured display of Eventcounter
// Constructor
public function Report_monilog() {
@ -89,6 +80,36 @@ class Report_monilog extends Report {
$this->_arrProperties[] = SYSLOG_MESSAGE;
$this->_arrProperties[] = MISC_CHECKSUM;
// Init Customfilters Array
$this->_arrCustomFilters['_maxHosts'] = array ( 'InternalID' => '_maxHosts',
'DisplayLangID' => 'ln_report_maxHosts_displayname',
'DescriptLangID'=> 'ln_report_maxHosts_description',
FILTER_TYPE => FILTER_TYPE_NUMBER,
'DefaultValue' => 20,
'MinValue' => 0,
'MaxValue' => 0,
);
$this->_arrCustomFilters['_maxEventsPerHost'] =
array ( 'InternalID' => '_maxEventsPerHost',
'DisplayLangID' => 'ln_report_maxEventsPerHost_displayname',
'DescriptLangID'=> 'ln_report_maxEventsPerHost_description',
FILTER_TYPE => FILTER_TYPE_NUMBER,
'DefaultValue' => 100,
'MinValue' => 0,
'MaxValue' => 0,
);
$this->_arrCustomFilters['_colorThreshold'] =
array ( 'InternalID' => '_colorThreshold',
'DisplayLangID' => 'ln_report_colorThreshold_displayname',
'DescriptLangID'=> 'ln_report_colorThreshold_description',
FILTER_TYPE => FILTER_TYPE_NUMBER,
'DefaultValue' => 10,
'MinValue' => 0,
'MaxValue' => 0,
);
}
/**
@ -108,13 +129,12 @@ class Report_monilog extends Report {
$res = $this->_streamObj->Open( $this->_arrProperties, true );
if ( $res == SUCCESS )
{
//
// // Verify Datasource first!
// if ( $this->verifyDataSource() == SUCCESS )
// {
// Set to common content variables
$this->SetCommonContentVariables();
// Set report specific content variables
$content["_colorThreshold"] = $this->_colorThreshold;
// --- Report logic starts here
$content["report_rendertime"] = "";

View File

@ -40,6 +40,15 @@ $content['ln_report_severity'] = "Type";
$content['ln_report_eventid'] = "Event ID";
$content['ln_report_description'] = "Description";
$content['ln_report_count'] = "Count";
$content['ln_report_maxHosts_displayname'] = "Max hosts";
$content['ln_report_maxHosts_description'] = "The maximum number of hosts which will be displayed.";
$content['ln_report_maxEventsPerHost_displayname'] = "Max Events per host";
$content['ln_report_maxEventsPerHost_description'] = "The maximum number of events displayed per host.";
$content['ln_report_colorThreshold_displayname'] = "Counter Threshold";
$content['ln_report_colorThreshold_description'] = "If the amount of consolidated events is higher then this threshold, the countfield will be marked red.";
$content['ln_report_'] = "";
$content['ln_report_'] = "";
$content['ln_report_'] = "";
$content['ln_report_'] = "";
$content['ln_report_'] = "";
$content['ln_report_'] = "";

View File

@ -113,12 +113,12 @@
<td class="line1" valign="top" align="center">{syslogseverity_text}</td>
<td class="line1" valign="top" align="center"><a href="http://kb.monitorware.com/kbsearch.php?sa=Search&origin=phplogcon&oid=id&q={id}" target="_blank">{id}</a></td>
<td class="line1" valign="top" align="left">{msg}</td>
<!-- IF ItemCount>10 -->
<!-- IF ItemCount>=$_colorThreshold -->
<td class="lineColouredWhite" valign="top" align="right" bgcolor="#990000"><b>{ItemCount}</b></td>
<!-- ENDIF ItemCount>10 -->
<!-- IF ItemCount<11 -->
<!-- ENDIF ItemCount>=$_colorThreshold -->
<!-- IF ItemCount<$_colorThreshold -->
<td class="lineColouredWhite" valign="top" align="right" bgcolor="#AAAAAA"><b>{ItemCount}</b></td>
<!-- ENDIF ItemCount<11 -->
<!-- ENDIF ItemCount<$_colorThreshold -->
</tr>

View File

@ -431,8 +431,8 @@ $content['LN_REPORTS_FILTER_MOVEDOWN'] = "Move filter down";
$content['LN_REPORTS_FILTER_REMOVE'] = "Remove filter";
$content['LN_REPORTS_FILTEREDITOR'] = "Filtereditor";
$content['LN_REPORTS_FILTERSTRING_ONLYEDITIF'] = "Only edit raw filterstring if you know what you are doing! Note if you change the filterstring, any changes made in the Filtereditor will be lost!";
$content['LN_REPORTS_'] = "";
$content['LN_REPORTS_'] = "";
$content['LN_REPORTS_ADVANCEDFILTERS'] = "Advanced filters";
$content['LN_REPORTS_ADVANCEDFILTERLIST'] = "List of advanced report filters";
$content['LN_REPORTS_'] = "";
$content['LN_REPORTS_'] = "";
$content['LN_REPORTS_'] = "";

View File

@ -204,10 +204,15 @@ if ( !$content['error_occured'] )
else
{
// --- Perform report output
$reportIncludePath = $gl_root_path . 'classes/reports/' . $myReportObj->_reportFileBasicName . "/";
// Init IncludePath
$reportIncludePath = $myReportObj->GetReportIncludePath();
// Include Custom language file if available
IncludeLanguageFile( $reportIncludePath . $myReportObj->_reportFileBasicName . ".lang.en.php" );
$myReportObj->InitReportLanguageFile($reportIncludePath);
// $reportIncludePath = $gl_root_path . 'classes/reports/' . $myReportObj->_reportFileBasicName . "/";
// IncludeLanguageFile( $reportIncludePath . $myReportObj->_reportFileBasicName . ".lang.en.php" );
// Init template Parser
$page = new Template();

View File

@ -190,10 +190,6 @@
<td align="center" class="{colcssclass}" width="50">
<button name="subop_edit" type="submit" value="{ROWCNT}" class="borderlessbuttons" title="{LN_REPORTS_FILTER_EDIT}"><img src="{MENU_EDIT}" width="16" alt="{LN_REPORTS_FILTER_EDIT}"></button>
<!--
<button name="subop_moveup" type="submit" value="{FilterFieldID}" class="borderlessbuttons" title="{LN_REPORTS_FILTER_MOVEUP}"><img src="{MENU_MOVE_UP}" width="16" alt="{LN_REPORTS_FILTER_MOVEUP}"></button>
<button name="subop_movedown" type="submit" value="{FilterFieldID}" class="borderlessbuttons" title="{LN_REPORTS_FILTER_MOVEDOWN}"><img src="{MENU_MOVE_DOWN}" width="16" alt="{LN_REPORTS_FILTER_MOVEDOWN}"></button>
-->
<button name="subop_delete" type="submit" value="{ROWCNT}" class="borderlessbuttons" title="{LN_REPORTS_FILTER_REMOVE}"><img src="{MENU_DELETE}" width="16" alt="{LN_REPORTS_FILTER_REMOVE}"></button>
</td>
</tr>
@ -213,6 +209,31 @@
</td>
</tr>
<tr>
<td align="left" class="cellmenu2_naked" width="150" valign="top" nowrap><b>{LN_REPORTS_ADVANCEDFILTERS}</b></td>
<td align="left" class="line1" width="100%">
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#DDDDDD" width="550" class="with_border_alternate">
<tr>
<td align="center" class="cellmenu1" colspan="4"><b>{LN_REPORTS_ADVANCEDFILTERLIST}</b></td>
</tr>
<!-- BEGIN CUSTOMFILTERS -->
<tr>
<td align="left" class="{colcssclass}" width="350">
<b>{fieldcaption}</b><br/>(<I>{fielddescription}</I>)
</td>
<td align="left" class="{colcssclass}" width="200">
<input type="text" name="fieldname" size="40" maxlength="255" value="{fieldvalue}">
</td>
</tr>
<!-- END CUSTOMFILTERS -->
</table>
</td>
</tr>
<tr>
<td align="left" class="cellmenu2" width="150" nowrap><b>{LN_REPORTS_SOURCEID}</b></td>
<td align="left" class="line2" width="100%">