Skip to content
Snippets Groups Projects
Commit 67e8a82f authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

ignore skipentries in timeline; added phpdocs

parent e7d4e5d2
No related branches found
No related tags found
No related merge requests found
...@@ -10,12 +10,15 @@ require_once 'cronlog.class.php'; ...@@ -10,12 +10,15 @@ require_once 'cronlog.class.php';
*/ */
class cronlogrenderer extends cronlog{ class cronlogrenderer extends cronlog{
/**
* minimal length for execution time of a job to be rendered in the timeline; value is in seconds
* @var integer
*/
protected $_iMinTime4Timeline = 60; protected $_iMinTime4Timeline = 60;
/** /**
* show date of last data and last access * show date of last data and last access; used in rendering methods to display it on top
* @param type $iLast * @param type $iLast timestamp of last log entry
* @return string * @return string
*/ */
protected function _renderAccessAndAge($iLast){ protected function _renderAccessAndAge($iLast){
...@@ -249,6 +252,11 @@ class cronlogrenderer extends cronlog{ ...@@ -249,6 +252,11 @@ class cronlogrenderer extends cronlog{
return $sHtml; return $sHtml;
} }
/**
* get html code for a joblist of the selected server
* it uses the filter for hidden joblog entries (aHidelogs in config)
* @return string
*/
public function renderJoblistOfAllServers(){ public function renderJoblistOfAllServers(){
$aData=array(); $aData=array();
foreach (array_keys($this->getServers()) as $sServer){ foreach (array_keys($this->getServers()) as $sServer){
...@@ -283,7 +291,7 @@ class cronlogrenderer extends cronlog{ ...@@ -283,7 +291,7 @@ class cronlogrenderer extends cronlog{
} }
$iGraphCounter++; $iGraphCounter++;
if(!$aData){ if(!$aData){
$aData=$this->getServerJobHistory(); $aData=$this->getServerJobHistory(false);
} }
$sDivId='vis-timeline-'.$iGraphCounter; $sDivId='vis-timeline-'.$iGraphCounter;
...@@ -448,6 +456,10 @@ class cronlogrenderer extends cronlog{ ...@@ -448,6 +456,10 @@ class cronlogrenderer extends cronlog{
return $sHtml; return $sHtml;
} }
/**
* get html code for a select box with all servers
* @return string
*/
public function renderServerlist($sSelectedItem=false){ public function renderServerlist($sSelectedItem=false){
$sHtml=''; $sHtml='';
$sHtml.='<option value="ALL"' $sHtml.='<option value="ALL"'
......
...@@ -21,13 +21,20 @@ class cronlog { ...@@ -21,13 +21,20 @@ class cronlog {
protected $_iExpiredJobsFailAfter = 60*30; // in sec protected $_iExpiredJobsFailAfter = 60*30; // in sec
protected $_aSkipJoblogs = array(); protected $_aSkipJoblogs = array();
protected $_aServers = false; protected $_aServers = array();
protected $_sActiveServer = false; protected $_sActiveServer = false;
protected $_sFileFilter_serverjoblog = '*joblog*.done'; protected $_sFileFilter_serverjoblog = '*joblog*.done';
protected $_sFileFilter_serverlog = '*.log'; protected $_sFileFilter_serverlog = '*.log';
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
/**
* init
* @return boolean
*/
public function __construct() { public function __construct() {
// read config // read config
...@@ -52,7 +59,7 @@ class cronlog { ...@@ -52,7 +59,7 @@ class cronlog {
/** /**
* get the full path of directory for caching * chaching: get the full path of directory for caching
* @return type * @return type
*/ */
protected function _getCacheDir(){ protected function _getCacheDir(){
...@@ -60,7 +67,7 @@ class cronlog { ...@@ -60,7 +67,7 @@ class cronlog {
} }
/** /**
* get full path of a caching item * caching: get full path of a caching item
* @param type $sTaskId * @param type $sTaskId
* @return type * @return type
*/ */
...@@ -69,13 +76,18 @@ class cronlog { ...@@ -69,13 +76,18 @@ class cronlog {
} }
/** /**
* get full path to a servers cronjob logdata * read logs: get full path to a servers cronjob logdata
* @return type * @return type
*/ */
protected function _getServerlogDir(){ protected function _getServerlogDir(){
return $this->_sDataDir.'/'.$this->_sActiveServer; return $this->_sDataDir.'/'.$this->_sActiveServer;
} }
/**
* caching: get cached data if they exist and aren't expired
* @param string $sTaskId
* @return boolean|array
*/
protected function _getCacheData($sTaskId){ protected function _getCacheData($sTaskId){
// DISABLE CACHE return false; // DISABLE CACHE return false;
$sFile=$this->_getCacheFile($sTaskId); $sFile=$this->_getCacheFile($sTaskId);
...@@ -90,6 +102,72 @@ class cronlog { ...@@ -90,6 +102,72 @@ class cronlog {
} }
return false; return false;
} }
/**
* read logs: parse a single line in the joblog and return has with all key value items
* @param string $sLine single line in the log
* @return array
*/
protected function _parseJoblogLine($sLine){
$aReturn=array();
// echo "DEBUG $sLine<br>";
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
$sLine=str_replace("\n", '', $sLine);
$sLine=str_replace(':', '", "', $sLine);
$sLine=str_replace('=', '": "', $sLine);
$sLine='{"'.$sLine.'"}';
// echo "DEBUG $sLine<br><br>";
$aReturn=json_decode($sLine, 1);
if(!is_array($aReturn)){
echo "not a JSON string<br>";
echo "DEBUG $sLine<br><br>";
die();
}
return $aReturn;
}
/**
* read logs: parse the whole cronwrapper logfile and return a hash
* @param string $sFile filename with full path
*/
protected function _parseLogfile($sFile) {
$aReturn=array(
'SCRIPTNAME'=>false,
'SCRIPTTTL'=>false,
'SCRIPTSTARTTIME'=>false,
'SCRIPTLABEL'=>false,
'SCRIPTENDTIME'=>false,
'SCRIPTEXECTIME'=>false,
'SCRIPTRC'=>false,
// 'SCRIPTOUT'=>array(),
);
$fileHandle = fopen($sFile, "r");
while (($line = fgets($fileHandle)) !== false) {
// get key ... the part before "="
$sKey=trim(preg_replace('/=.*/', '', $line));
if($sKey && isset($aReturn[$sKey])){
// add value ... the part behind "="
$aReturn[$sKey]=preg_replace('/^([A-Z]*\=)/', '', $line);
}
}
fclose($fileHandle);
// fetch unit timestamp from date values (they are like "2018-09-30 03:40:05, 1538278805")
$aReturn['SCRIPTSTARTTIME']=(int)preg_replace('/.*,\ /', '', $aReturn['SCRIPTSTARTTIME']);
$aReturn['SCRIPTENDTIME']=(int)preg_replace('/.*,\ /', '', $aReturn['SCRIPTSTARTTIME']);
// remove " s" from exec time value
$aReturn['SCRIPTEXECTIME']=preg_replace('/\ s$/', '', $aReturn['SCRIPTEXECTIME']);
return $aReturn;
}
/**
* caching: write new data; it returns the success of write operation as bool
* @param string $sTaskId
* @param [any] $data data to store; can be any serializable value
* @return boolean
*/
protected function _writeCacheData($sTaskId, $data){ protected function _writeCacheData($sTaskId, $data){
$sFile=$this->_getCacheFile($sTaskId); $sFile=$this->_getCacheFile($sTaskId);
// echo "WRITE cache $sFile<br>"; // echo "WRITE cache $sFile<br>";
...@@ -101,7 +179,7 @@ class cronlog { ...@@ -101,7 +179,7 @@ class cronlog {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** /**
* get current server * get currently selected server
* @return string * @return string
*/ */
public function getServer(){ public function getServer(){
...@@ -138,32 +216,12 @@ class cronlog { ...@@ -138,32 +216,12 @@ class cronlog {
return $this->_aServers; return $this->_aServers;
} }
/**
*
*/
protected function _parseJoblogLine($sLine){
$aReturn=array();
// echo "DEBUG $sLine<br>";
// job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0
$sLine=str_replace("\n", '', $sLine);
$sLine=str_replace(':', '", "', $sLine);
$sLine=str_replace('=', '": "', $sLine);
$sLine='{"'.$sLine.'"}';
// echo "DEBUG $sLine<br><br>";
$aReturn=json_decode($sLine, 1);
if(!is_array($aReturn)){
echo "not a JSON string<br>";
echo "DEBUG $sLine<br><br>";
die();
}
return $aReturn;
}
/** /**
* get logs from jobfilea of the current or given server * get logs from jobfilea of the current or given server
* @param boolean $bUseSkip hide jobs if their label matches the skip list; default: true
* @return array * @return array
*/ */
public function getServerJobHistory(){ public function getServerJobHistory($bUseSkip=true){
$aReturn=array(); $aReturn=array();
$sTaskId=__FUNCTION__.'-'.$this->_sActiveServer; $sTaskId=__FUNCTION__.'-'.$this->_sActiveServer;
...@@ -180,7 +238,7 @@ class cronlog { ...@@ -180,7 +238,7 @@ class cronlog {
while (($line = fgets($fileHandle)) !== false) { while (($line = fgets($fileHandle)) !== false) {
// send the current file part to the browser // send the current file part to the browser
$aData=$this->_parseJoblogLine($line); $aData=$this->_parseJoblogLine($line);
if(array_search($aData['job'], $this->_aSkipJoblogs)===false){ if(!$bUseSkip && array_search($aData['job'], $this->_aSkipJoblogs)===false){
$aReturn[$aData['start']]=$aData; $aReturn[$aData['start']]=$aData;
} }
} }
...@@ -191,38 +249,6 @@ class cronlog { ...@@ -191,38 +249,6 @@ class cronlog {
return $aReturn; return $aReturn;
} }
protected function _parseLogfile($sFile) {
$aReturn=array(
'SCRIPTNAME'=>false,
'SCRIPTTTL'=>false,
'SCRIPTSTARTTIME'=>false,
'SCRIPTLABEL'=>false,
'SCRIPTENDTIME'=>false,
'SCRIPTEXECTIME'=>false,
'SCRIPTRC'=>false,
// 'SCRIPTOUT'=>array(),
);
$fileHandle = fopen($sFile, "r");
while (($line = fgets($fileHandle)) !== false) {
// get key ... the part before "="
$sKey=trim(preg_replace('/=.*/', '', $line));
if($sKey && isset($aReturn[$sKey])){
// add value ... the part behind "="
$aReturn[$sKey]=preg_replace('/^([A-Z]*\=)/', '', $line);
}
}
fclose($fileHandle);
// fetch unit timestamp from date values (they are like "2018-09-30 03:40:05, 1538278805")
$aReturn['SCRIPTSTARTTIME']=(int)preg_replace('/.*,\ /', '', $aReturn['SCRIPTSTARTTIME']);
$aReturn['SCRIPTENDTIME']=(int)preg_replace('/.*,\ /', '', $aReturn['SCRIPTSTARTTIME']);
// remove " s" from exec time value
$aReturn['SCRIPTEXECTIME']=preg_replace('/\ s$/', '', $aReturn['SCRIPTEXECTIME']);
return $aReturn;
}
/** /**
* get logs from jobfilea of the current or given server * get logs from jobfilea of the current or given server
...@@ -246,6 +272,12 @@ class cronlog { ...@@ -246,6 +272,12 @@ class cronlog {
// public setter // public setter
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/**
* set which server is selected
* The given server must exist as directory (that contains its logs)
* @param string $sServer server name
* @return string
*/
public function setServer($sServer){ public function setServer($sServer){
$this->_sActiveServer=false; $this->_sActiveServer=false;
if($sServer==='ALL'){ if($sServer==='ALL'){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment