Location: PHPKode > projects > Php-Logging-System > phplogsys-1.1.4/includes/syslog-ngstats.php
<?php
$inputValError = array();
require_once(BASE_PATH . '/parse_syslog-ng.php');

$pieces = explode('&', $ParamsGET);
$linkParamsGET = '';
foreach($pieces as $value){
	if(!strstr($value, 'priority[]=') && !strstr($value, 'excludepriority=') && !strstr($value, 'facility[]=') && !strstr($value, 'excludefacility=') && !strstr($value, 'offset=') && !strstr($value, 'pageId=') && $value){
		$linkParamsGET .= $value.'&';
	}
}
$linkParamsGET .= 'pageId=Search+Syslog-ng';

$facilityarray = array();
$priorityarray = array('debug', 'info', 'notice', 'warning', 'err', 'crit', 'alert', 'emerg');
//------------------------------------------------------------------------
// Use cache?
//------------------------------------------------------------------------
if(USE_CACHE && table_exists(CACHETABLENAME, $dbLink)) {
	// Get the timestamp for the last update.
	$sql = 'SELECT updatetime FROM ' . CACHETABLENAME . ' LIMIT 1';
	$queryresult = perform_query($sql, $dbLink);
	$row = fetch_array($queryresult);
	$cacheUpdate = $row['updatetime'];

	// Print info about the cache.
	echo '<table class="searchform">';
	echo '<tr class="lighter"><td>';
	echo '<b>USING CACHE TO POPULATE HOST AND FACILITY FIELDS, </b>';
	echo '<br />Cache last updated on ', $cacheUpdate, ', ';
	echo '</td></tr></table>';

	// Get the FACILITY list
	$sql = 'SELECT DISTINCT value FROM '.CACHETABLENAME.' WHERE type=\'FACILITY\'';
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($facilityarray, $line['value']);
	}
	sort($facilityarray);
}
else {
//------------------------------------------------------------------------
// If no cache then get possible values for facility and host from table.
//------------------------------------------------------------------------
	$sql = 'SELECT DISTINCT facility FROM '.$table;
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($facilityarray, $line['facility']);
	}
	sort($facilityarray);
}

//------------------------------------------------------------------------
// Create the complete SQL statement
//------------------------------------------------------------------------
if($table) {
	$srcTable = $table;
}
else {
	$srcTable = DEFAULTLOGTABLE;
}

$query = 'SELECT count(*) AS totallogs, facility, priority FROM '.$srcTable.' ';

if($where) {
	$query = $query.'WHERE '.$where;
}
$query = $query.'GROUP BY facility, priority';

//------------------------------------------------------------------------
// Execute the query
// The FOUND_ROWS function returns the value from the SQL_CALC_FOUND_ROWS
// count.
//------------------------------------------------------------------------
$results = perform_query($query, $dbLink);
//========================================================================
// END: BUILD AND EXECUTE SQL STATEMENT
// AND BUILD PARAMETER LIST FOR HTML GETS
//========================================================================

//========================================================================
// BEGIN: PREPARE RESULT ARRAY
//========================================================================
$resultarray = array();
//------------------------------------------------------------------------
// Collapse consecutive identical messages into one line
//------------------------------------------------------------------------
while ($row = fetch_array($results)) $resultarray[$row['facility']][$row['priority']] = $row['totallogs'];
//========================================================================
// END: PREPARE RESULT ARRAY
//========================================================================

//========================================================================
// BEGIN: BUILDING THE HTML PAGE
//========================================================================
// Print result sub-header
require_once(BASE_PATH . '/syslog-ng_result_subheader.php');

echo '<table><tr class="resultsheader"><td>FACILITY</td>';
foreach($priorityarray as $priority) echo '<td>', strtoupper($priority), '</td>';
echo '<td>TOTAL</td></tr>';
$color = 'lighter';
foreach($facilityarray as $facility) {
	$total = 0;
	if($color == 'darker') {
		$color = 'lighter';
	}
	else {
		$color = 'darker';
	}
	echo '<tr class="', $color, '"><td nowrap>', $facility, '</td>';
	foreach($priorityarray as $priority) {
		if($resultarray[$facility][$priority] > 0){
			if($priority == 'debug') {
				echo '<td nowrap style="text-align: right;" class="sev0">';
			}
			elseif($priority == 'info') {
				echo '<td nowrap style="text-align: right;" class="sev1">';
			}
			elseif ($priority == 'notice') {
				echo '<td nowrap style="text-align: right;" class="sev2">';
			}
			elseif ($priority == 'warning') {
				echo '<td nowrap style="text-align: right;" class="sev3">';
			}
			elseif ($priority == 'err') {
				echo '<td nowrap style="text-align: right;" class="sev4">';
			}
			elseif ($priority == 'crit') {
				echo '<td nowrap style="text-align: right;" class="sev5">';
			}
			elseif ($priority == 'alert') {
				echo '<td nowrap style="text-align: right;" class="sev6">';
			}
			elseif ($priority == 'emerg') {
				echo '<td nowrap style="text-align: right;" class="sev7">';
			}
		}else{
			echo '<td nowrap style="text-align: right;padding: 1px 11px 1px 11px;">';
		}
		if(isset($resultarray[$facility][$priority])){
			$total += $resultarray[$facility][$priority];
			echo '<a style="font-weight: normal;" href="', $_SERVER['PHP_SELF'], '?priority[]=', $priority, '&facility[]=', $facility, '&excludepriority=&excludefacility=&offset=0&', $linkParamsGET, '">', commify($resultarray[$facility][$priority]), '</a></td>';
		}else{
			echo '0</td>';
		}
	}
	echo '<td nowrap style="text-align: right;"><a style="font-weight: normal;" href="', $_SERVER['PHP_SELF'], '?facility[]=', $facility, '&excludepriority=&excludefacility=&offset=0&', $linkParamsGET, '">', commify($total), '</a></td></tr>';
}
if($color == 'darker') {
	$color = 'lighter';
}
else {
	$color = 'darker';
}
echo '<tr class="', $color, '"><td nowrap>TOTAL</td>';
$gtotal = 0;
foreach($priorityarray as $priority) {
	$total = 0;
	foreach($facilityarray as $facility) $total += $resultarray[$facility][$priority];
	if($total > 0){
		if($priority == 'debug') {
			echo '<td nowrap style="text-align: right;" class="sev0">';
		}
		elseif($priority == 'info') {
			echo '<td nowrap style="text-align: right;" class="sev1">';
		}
		elseif ($priority == 'notice') {
			echo '<td nowrap style="text-align: right;" class="sev2">';
		}
		elseif ($priority == 'warning') {
			echo '<td nowrap style="text-align: right;" class="sev3">';
		}
		elseif ($priority == 'err') {
			echo '<td nowrap style="text-align: right;" class="sev4">';
		}
		elseif ($priority == 'crit') {
			echo '<td nowrap style="text-align: right;" class="sev5">';
		}
		elseif ($priority == 'alert') {
			echo '<td nowrap style="text-align: right;" class="sev6">';
		}
		elseif ($priority == 'emerg') {
			echo '<td nowrap style="text-align: right;" class="sev7">';
		}
	}else{
		echo '<td nowrap style="text-align: right;padding: 1px 11px 1px 11px;">';
	}
	echo '<a style="font-weight: normal;" href="', $_SERVER['PHP_SELF'], '?priority[]=', $priority, '&excludepriority=&excludefacility=&offset=0&', $linkParamsGET, '">', commify($total), '</a></td>';
	$gtotal += $total;
}
echo '<td nowrap style="text-align: right;">', commify($gtotal), '</td></tr>';

echo '</table>';

//========================================================================
// END: BUILDING THE HTML PAGE
//========================================================================
?>
Return current item: Php-Logging-System