示例#1
0
	public function action()
	{
		// Objects
		$xml = $this->getXML();
		$xml->addFullTag("view_log",$this->_generic->getFullPath("SLS_Bo","LogsMonitoring",array(),false));
		
		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		
		// Get the existing logs
		$dates = array();
		$all = array();
		$handle = opendir($this->_generic->getPathConfig("logs")."monitoring");
		
		// Foreach directories 
		while (false !== ($dir = readdir($handle)))
		{
			if (is_dir($this->_generic->getPathConfig("logs")."/monitoring/".$dir) && substr($dir, 0, 1) != ".") 
			{				
				$handle2 = opendir($this->_generic->getPathConfig("logs")."/monitoring/".$dir);				
				while (false !== ($file = readdir($handle2)))
				{					
					if (!is_dir($this->_generic->getPathConfig("logs")."/monitoring/".$dir."/".$file) && substr($file, 0, 1) != ".") 
					{
						$date = explode("-",substr($file,0,10));						
						if (!in_array(substr($file,0,10),$dates))
						{
							$array = array("year"=>$date[0],"month"=>$date[1],"day"=>$date[2]);
							array_push($all,$array);
							array_push($dates,substr($file,0,10));
						}
					}
				}
			}
		}
		if (!empty($all))
		{
			$all = SLS_String::arrayMultiSort($all,array(array('key'=>'year','sort'=>'desc'),array('key'=>'month','sort'=>'desc'),array('key'=>'day','sort'=>'desc')));
			
			$xml->startTag("logs");
			foreach($all as $allC)			
			{
				$dateL = new SLS_Date($allC["year"]."-".$allC["month"]."-".$allC["day"]);
				$xml->startTag("log");
				$xml->addFullTag("year",$allC["year"],true);
				$xml->addFullTag("month",$allC["month"],true);
				$xml->addFullTag("day",$allC["day"],true);
				$xml->addFullTag("litteral",ucwords($dateL->getDate("FULL_LITTERAL")));
				$xml->endTag("log");
			}
			$xml->endTag("logs");
		}
		
		$this->saveXML($xml);
	}
	public function action()
	{
		// Objects
		$xml = $this->getXML();

		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		
		$date = $this->_http->getParam("date");
		$dateE = explode("-",$date);
		$dateL = new SLS_Date($date);
		
		if (is_array($dateE) && count($dateE) == 3 && is_dir($this->_generic->getPathConfig("logs").$dateE[0]."-".$dateE[1]))
		{
			$content = "";
			$i = 0;
			
			while(file_exists($this->_generic->getPathConfig("logs").$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log"))
			{
				$content .= file_get_contents($this->_generic->getPathConfig("logs").$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log");
				$i++;
			}
			$errors = explode($date,$content);
			$xml->startTag("errors");
			$xml->addFullTag("date",$dateL->getDate("FULL_LITTERAL"));
			foreach($errors as $error)
			{
				if (!empty($error))
				{
					$stack = explode("\n",$error);
					$xml->startTag("error");	
					$xml->addFullTag("title",$date.$stack[0]);
					$xml->startTag("traces");
					for($j=1 ; $j<$count=count($stack) ; $j++)
					{
						if (!empty($stack[$j]))
						{
							$trace = explode("in file",$stack[$j]);
							$xml->startTag("trace");
							$xml->addFullTag("message",$trace[0],true);
							$xml->addFullTag("file","in file".$trace[1],true);
							$xml->endTag("trace");
						}
					}
					$xml->endTag("traces");
					$xml->endTag("error");
				}
			}
			$xml->endTag("errors");			
		}
		
		$this->saveXML($xml);
	}
	public function action()
	{
		// Objects
		$xml = $this->getXML();

		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		
		$date = $this->_http->getParam("date");
		$dateE = explode("-",$date);
		$dateL = new SLS_Date($date);
		
		if (is_array($dateE) && count($dateE) == 3 && is_dir($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]))
		{
			$content = "";
			$i = 0;
			
			while(file_exists($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log"))
			{
				$content .= file_get_contents($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log");
				$i++;
			}
			$batchs = explode("#|end|#",$content);
			
			$xml->startTag("batchs");
			$xml->addFullTag("date",$dateL->getDate("FULL_LITTERAL"));
			foreach($batchs as $batch)
			{
				if (!empty($batch))
				{
					$lines = explode("\n",$batch);
					
					$times = array ("Render"			=> 0,
									"XML/XSL Parsing"	=> 0,									
									"MySQL Query"		=> 0,
									"Controller Action"	=> 0,
									"Controller Front"	=> 0,
									"Controller Static" => 0);
					$msg = "";
					$totalTime = 0;
					$endTime = 0;
					
					$xml->startTag("batch");
						$xml->startTag("lines");
						foreach($lines as $line)
						{
							$infos = explode("||",$line);
							$infos = array_map('trim',$infos);
							
							if (count($infos) > 4)
							{
								$times[$infos[0]] += $infos[2];
								if ($infos[0] == "Render")
								{
									$totalTime = $infos[2];
									$endTime = SLS_String::substrAfterFirstDelimiter($infos[1]," ");
								}
								if ($infos[0] == "Controller Front")								
									$msg = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($infos[3],")"),"(");
								
								$xml->startTag("line");
									$xml->addFullTag("msg",$infos[3],true);
									$xml->addFullTag("type",$infos[0],true);
									$xml->addFullTag("more",str_replace(array("|n|","|t|","    "),array("<br />","&#160;&#160;","&#160;&#160;&#160;&#160;"),$infos[4]),true);
									$xml->addFullTag("time",SLS_String::substrAfterFirstDelimiter($infos[1]," "),true);
									$xml->addFullTag("duration",$infos[2],true);
								$xml->endTag("line");
							}
						}
						$xml->endTag("lines");
						$xml->startTag("infos");
							$xml->addFullTag("name",$endTime." - ".$msg,true);
							$xml->startTag("times");
								$xml->addFullTag("total",$totalTime,true);
								foreach($times as $key => $value)
									$xml->addFullTag(SLS_String::stringToUrl(trim($key),"_"),$value,true);
							$xml->endTag("times");
						$xml->endTag("infos");
						$sum = 0;
						$xml->startTag("ratios");
						foreach($times as $key => $value)
						{
							if ($key == "Render")
								continue;
							else
								$sum += $value;
								
							$xml->startTag("ratio");
								$xml->addFullTag("label",str_replace(" ","+",trim($key)),true);
								$xml->addFullTag("duration",$times[$key],true);								
								$xml->addFullTag("degree",($totalTime > 0) ? 360 * $value / $totalTime : "360",true);
							$xml->endTag("ratio");
						}
						if ($totalTime - $sum > 0)
						{
							$xml->startTag("ratio");
								$xml->addFullTag("label","Others",true);
								$xml->addFullTag("duration",$sum,true);	
								$xml->addFullTag("degree",($totalTime > 0) ? 360 * $sum / $totalTime : "360",true);
							$xml->endTag("ratio");
						}
						$xml->endTag("ratios");
					$xml->endTag("batch");
				}
			}
			$xml->endTag("batchs");			
		}
		
		$this->saveXML($xml);
	}
	public function getSlsGraphXml(&$xml, $slsGraph)
	{
		$xml->startTag('sls_graph');
		if(empty($slsGraph))
		{
			$xml->endTag('sls_graph');
			return;
		}
		
		$colors = array(
			'#ff275f',
			'#980067',
			'#0094a5',
			'#96be12',
			'#ffba00',
			'#ed7807',
			'#ba3ecc',
			'#07b3da',
			'#408cd0',
			'#004e8e',
			'#f06eaa',
			'#a764a7',
			'#81c99b',
			'#abd273',
			'#faae5d',
			'#f16c4f',
			'#f4979c',
			'#bc8bbe',
			'#8292c9',
			'#67c4e8'
		);

		$labels = array('SLS_GRAPH_TYPE_PIE' => "Pie Chart",
						'SLS_GRAPH_TYPE_BAR' => "Bar Chart",
						'SLS_GRAPH_TYPE_PIVOT' => "Pivot Table",
						'SLS_GRAPH_TYPE_LIST' => "List",
						'SLS_AGGREGATION_TYPE_SUM' => "SUM",
						'SLS_AGGREGATION_TYPE_AVG' => "AVG",
						'SLS_AGGREGATION_TYPE_COUNT' => "COUNT",
						'SLS_AGGREGATION_TYPE_SUM_LABEL' => "Sum",
						'SLS_AGGREGATION_TYPE_AVG_LABEL' => "Average",
						'SLS_AGGREGATION_TYPE_COUNT_LABEL' => "Total",
						'SLS_QUERY_OPERATOR_LIKE' => "LIKE",
						'SLS_QUERY_OPERATOR_NOTLIKE' => "NOT LIKE",
						'SLS_QUERY_OPERATOR_STARTWITH' => "START WITH",
						'SLS_QUERY_OPERATOR_ENDWITH' => "END WITH",
						'SLS_QUERY_OPERATOR_EQUAL' => "EQUAL",
						'SLS_QUERY_OPERATOR_NOTEQUAL' => "NOT EQUAL",
						'SLS_QUERY_OPERATOR_IN' => "IN",
						'SLS_QUERY_OPERATOR_NOTIN' => "NOT IN",
						'SLS_QUERY_OPERATOR_LT' => "LESS THAN",
						'SLS_QUERY_OPERATOR_LTE' => "LESS THAN EQUAL",
						'SLS_QUERY_OPERATOR_GT' => "GREATER THAN",
						'SLS_QUERY_OPERATOR_GTE' => "GREATER THAN EQUAL",
						'SLS_QUERY_OPERATOR_NULL' => "IS NULL",
						'SLS_QUERY_OPERATOR_NOTNULL' => "IS NOT NULL");
		
		foreach ($slsGraph->getParams() as $key => $value)
		{
			if($key =='sls_graph_date_add')
			{
				if($value != '0000-00-00 00:00:00')
				{
					$date = new SLS_Date($value);
					$value = $date->getDate('DATE');
				}
				else
					$value = '-';
			}
			else if($key == 'sls_graph_type')
				$xml->addFullTag($key.'_label', $labels['SLS_GRAPH_TYPE_'.mb_strtoupper($value, 'UTF-8')], true);

			$xml->addFullTag($key, $value, true);
		}

		$this->_generic->useModel("Sls_graph_query",$this->defaultDb,"sls");
		$className = ucfirst($this->defaultDb)."_Sls_graph_query";
		$slsGraphQuery = new $className();
		$slsGraphQuery->getModel($slsGraph->__get("sls_graph_query_id"));
		$request = $this->getSlsGraphQueryRequest($slsGraphQuery->sls_graph_query_id);
		$requestRender = str_replace(array("\t"),array(str_repeat(" ",4)),$request);		
		
		$xml->addFullTag('sls_graph_query', $requestRender, true);

		$this->sql->changeDb($slsGraphQuery->__get("sls_graph_query_db_alias"));
		$results = $this->sql->select($request);
		if($results === false)
		{
			$xml->addFullTag('sls_graph_error', 'Invalid SQL query',true);
		}
		else
		{
			if($slsGraph->sls_graph_type == 'pie')
			{
				$xml->startTag('sls_graph_data');

				$this->_generic->useModel("Sls_graph_query_group",$this->defaultDb,"sls");
				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup = new $className();
				$groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc")));
				$columnGroupName = $groups[0]->sls_graph_query_group_column;

				foreach($results as $result)
				{
					$xml->startTag('sls_graph_data_line');
					$xml->addFullTag('sls_graph_data_legend', (!empty($result->legend)) ? $result->legend : "Unknown", true);
					$xml->addFullTag('sls_graph_data_count', $result->count, true);
					$xml->endTag('sls_graph_data_line');
				}
				$xml->endTag('sls_graph_data');
			}
			else if($slsGraph->sls_graph_type == 'bar')
			{
				$this->_generic->useModel("Sls_graph_query_group",$this->defaultDb,"sls");
				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup = new $className();
				$this->_generic->useModel("Sls_graph_query_column",$this->defaultDb,"sls");
				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				$slsGraphQueryColumn = new $className();

				$xml->startTag('sls_graph_data');

				$groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc")));
				$columnAggregation = array_shift($slsGraphQueryColumn->searchModels("sls_graph_query_column",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_column_id","order"=>"asc"))));
				$columnAggregationFunction = $columnAggregation->sls_graph_query_column_aggregation;
				$columnAggregationName = $columnAggregation->sls_graph_query_column_name;
				$columnGroupName = $groups[0]->sls_graph_query_group_column;
				if(count($groups) > 1)
					$columnStackedName = $groups[1]->sls_graph_query_group_column;
				else
					$columnStackedName = '';

				if ($slsGraphQuery->sls_graph_query_db_alias != $this->sql->getCurrentDb())
					$this->sql->changeDb($slsGraphQuery->sls_graph_query_db_alias);
				$columnsComment = $this->sql->showColumns($slsGraphQuery->sls_graph_query_table);
				$tablesComment = $this->sql->showTables();

				$columnGroupComment = $this->array_pdo_search($columnsComment, 'Field', $columnGroupName)->Comment;
				$columnAggregationComment = $this->array_pdo_search($columnsComment, 'Field', $columnAggregationName)->Comment;

				if(!empty($columnStackedName))
					$columnStackedComment = $this->array_pdo_search($columnsComment, 'Field', $columnStackedName)->Comment;
				else
					$columnStackedComment = '';
				$tableComment = $this->array_pdo_search($tablesComment, 'Name', $slsGraphQuery->sls_graph_query_table)->Comment;

				$xml->addFullTag('sls_graph_data_aggregation_function', $columnAggregationFunction, true);

				$xml->addFullTag('sls_graph_data_legend_y', ($columnAggregationFunction == 'count' ? $tableComment : ($columnAggregationComment).' - '.$labels['SLS_AGGREGATION_TYPE_'.strtoupper($columnAggregationFunction).'_LABEL']), true);
				$xml->addFullTag('sls_graph_data_legend_x', $columnGroupComment, true);
				$xml->addFullTag('sls_graph_data_legend_stacked', $columnStackedComment, true);
				$xml->addFullTag('sls_graph_data_stacked', empty($columnStackedName) ? 'false' : 'true', true);

				$resultsGroup = array();
				$resultsGroupId = array();
				foreach($results as $result)
				{
					if(!in_array($result->legend_group_id, $resultsGroupId))
					{
						array_push($resultsGroup, $result);
						array_push($resultsGroupId, $result->legend_group_id);
					}
				}

				foreach($resultsGroup as $resultGroup)
				{
					$xml->startTag('sls_graph_data_line');
					$xml->addFullTag('sls_graph_data_legend', (!empty($resultGroup->legend_group)) ? $resultGroup->legend_group : "Unknown",true);
					$xml->addFullTag('sls_graph_data_value', round($resultGroup->value, 2),true);

					if(!empty($columnStackedName))
					{
						$xml->startTag('sls_graph_sub_data');
						foreach($results as $result)
						{
							if($result->legend_group == $resultGroup->legend_group)
							{
								$xml->startTag('sls_graph_sub_data_line');
								$xml->addFullTag('sls_graph_sub_data_legend', $result->legend_stacked, true);
								$xml->addFullTag('sls_graph_sub_data_value', round($result->value, 2), true);
								$xml->endTag('sls_graph_sub_data_line');
							}
						}
						$xml->endTag('sls_graph_sub_data');
					}

					$xml->endTag('sls_graph_data_line');
				}

				$xml->endTag('sls_graph_data');
				
			}
			else if($slsGraph->sls_graph_type == 'pivot')
			{
				$this->_generic->useModel("Sls_graph_query_group",$this->defaultDb,"sls");
				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup = new $className();
				$this->_generic->useModel("Sls_graph_query_column",$this->defaultDb,"sls");
				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				$slsGraphQueryColumn = new $className();

				$xml->startTag('sls_graph_data');

				$groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc")));
				$columnAggregation = array_shift($slsGraphQueryColumn->searchModels("sls_graph_query_column",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_column_id","order"=>"asc"))));
				$columnAggregationFunction = $columnAggregation->sls_graph_query_column_aggregation;
				$columnAggregationName = $columnAggregation->sls_graph_query_column_name;
				$columnLineName = $groups[0]->sls_graph_query_group_column;
				$columnColumndName = $groups[1]->sls_graph_query_group_column;

				if ($slsGraphQuery->sls_graph_query_db_alias != $this->sql->getCurrentDb())
					$this->sql->changeDb($slsGraphQuery->sls_graph_query_db_alias);
				$columnsComment = $this->sql->showColumns($slsGraphQuery->sls_graph_query_table);
				$tablesComment = $this->sql->showTables();

				$columnGroupComment = $this->array_pdo_search($columnsComment, 'Field', $columnLineName)->Comment;
				$columnAggregationComment = $this->array_pdo_search($columnsComment, 'Field', $columnAggregationName)->Comment;
				$columnStackedComment = $this->array_pdo_search($columnsComment, 'Field', $columnColumndName)->Comment;

				$tableComment = $this->array_pdo_search($tablesComment, 'Name', $slsGraphQuery->sls_graph_query_table)->Comment;

				$resultsLines = array();
				$resultsLinesId = array();
				foreach($results as $result)
				{
					if(!in_array($result->legend_line_id, $resultsLinesId))
					{
						array_push($resultsLinesId, $result->legend_line_id);
						array_push($resultsLines, $result);
					}
				}

				$resultsColumns = array();
				$resultsColumnsId = array();
				foreach($results as $result)
				{
					if(!in_array($result->legend_column_id, $resultsColumnsId))
					{
						array_push($resultsColumnsId, $result->legend_column_id);
						array_push($resultsColumns, $result);
					}
				}

				foreach($resultsLines as $resultsLine)
				{
					$xml->startTag('sls_graph_data_line');
					$xml->addFullTag('sls_graph_data_legend',(empty($resultsLine->legend_line)) ? 'Unknown' : $resultsLine->legend_line, true);

					$xml->startTag('sls_graph_sub_data');
					foreach($resultsColumns as $resultsColumn)
					{
						$xml->startTag('sls_graph_sub_data_line');
						$result = $this->array_pdo_multiple_search($results, array('legend_line_id' => $resultsLine->legend_line_id, 'legend_column_id' => $resultsColumn->legend_column_id));
						$value = !empty($result) ? $result->value : 0;
						$xml->addFullTag('sls_graph_sub_data_legend', empty($resultsColumn->legend_column) ? 'Unknown' : $resultsColumn->legend_column, true);
						$xml->addFullTag('sls_graph_sub_data_value', round($value, 2), true);
						$xml->endTag('sls_graph_sub_data_line');
					}
					$xml->endTag('sls_graph_sub_data');
					$xml->endTag('sls_graph_data_line');
				}

				$xml->endTag('sls_graph_data');
			}
			else if($slsGraph->sls_graph_type == 'list')
			{
				$xml->startTag('sls_graph_data');

				foreach($results as $result)
				{
					$xml->startTag('sls_graph_data_line');
					$xml->startTag('sls_graph_sub_data');
					foreach($result as $key => $value)
					{
						$xml->startTag('sls_graph_sub_data_line');
							$xml->addFullTag('sls_graph_sub_data_legend', $key, true);
							$xml->addFullTag('sls_graph_sub_data_value', $value, true);
						$xml->endTag('sls_graph_sub_data_line');
					}
					$xml->endTag('sls_graph_sub_data');
					$xml->endTag('sls_graph_data_line');
				}
				$xml->endTag('sls_graph_data');
			}
		}
		
		$xml->startTag('sls_graph_colors');
			foreach($colors as $color)
				$xml->addFulLTag('sls_graph_color', $color, true);
		$xml->endTag('sls_graph_colors');

		$xml->endTag('sls_graph');
	}