<?php require_once 'cronlog.class.php'; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * Description of cronlog-renderer * * @author hahn */ class cronlogrenderer extends cronlog{ //put your code here /** * get html code for a table with events of executed cronjobs * * @param array $aData result of $oCL->getServerLogs() * @return string */ public function renderJoblist($aData){ $sHtml=''; $sTblHead=''; // job=dok-kvm-instances:host=kalium:start=1538358001:end=1538358001:exectime=0:ttl=60:rc=0 foreach($aData as $aEntry){ if(!$sTblHead){ foreach(array('start', 'end', 'job', 'host', 'exectime', 'ttl', 'rc') as $sKey){ $sTblHead.='<th>'.$sKey.'</th>'; } } $sHtml.='<tr>' . '<td>'.date("Y-m-d H:i:s", $aEntry['start']).'</td>' . '<td>'.date("Y-m-d H:i:s", $aEntry['end']).'</td>' . '<td>'.$aEntry['job'].'</td>' . '<td>'.$aEntry['host'].'</td>' . '<td>' .$aEntry['exectime'].'s' .($aEntry['exectime']>100 ? ' ('.round($aEntry['exectime']/60).'min)' : '') . '</td>' . '<td>'.$aEntry['ttl'].'</td>' . '<td>'.$aEntry['rc'].'</td>' . '</tr>' ; } return '<table>' . '<thead><tr>'.$sTblHead.'</tr></thead>' . '<tbody>' .$sHtml .'</tbody>' . '</table>'; } /** * get html code for a timeline with events of executed cronjobs * * TODO: * for rendering of several hosts ... see grouping in * http://visjs.org/examples/timeline/groups/groupsOrdering.html * * @param array $aData result of $oCL->getServerLogs() * @return string */ public function renderJobGraph($aData){ $sHtml=''; static $iGraphCounter; if(!isset($iGraphCounter)){ $iGraphCounter=0; } $iGraphCounter++; $sDivId='vis-timeline-'.$iGraphCounter; $aDataset=array(); $iEntry=0; foreach($aData as $aEntry){ $iEntry++; $aDataset[]=array( 'id'=>$iEntry, 'start'=>date("Y-m-d H:i:s", $aEntry['start']), 'end'=>date("Y-m-d H:i:s", $aEntry['end']), 'content'=>$aEntry['job'].'@'.$aEntry['host'], 'className'=>'timeline-result-'.($aEntry['rc'] ? 'error' : 'ok'), 'title'=>'<strong>'.$aEntry['job'].'@'.$aEntry['host'].'</strong><br>' . 'start: ' . date("Y-m-d H:i:s", $aEntry['start']).'<br>' . 'end: ' . date("Y-m-d H:i:s", $aEntry['end']).'<br>' . 'exectime: ' .$aEntry['exectime'].'s' .($aEntry['exectime']>100 ? ' ('.round($aEntry['exectime']/60).'min)' : '') . '<br>' . 'rc = ' . $aEntry['rc'].'<br>' , ); } $sHtml.=' <!-- START '.__METHOD__.' --> <div id="'.$sDivId.'"></div> <script type="text/javascript"> // DOM element where the Timeline will be attached var container = document.getElementById("'.$sDivId.'"); // Create a DataSet (allows two way data-binding) var items = new vis.DataSet('.json_encode($aDataset).'); // Configuration for the Timeline var options = {}; // Create a Timeline var timeline = new vis.Timeline(container, items, options); </script> <!-- ENDE '.__METHOD__.'--> '; return $sHtml; } }