<?php
/*
* class system stat
* just too fat
*
*/
Class SystemReport extends ControllerBase {
private $ping;
private $agent;
private $servmondef;
private $servicesdef;
private $netmap;
public function __construct(){
parent::__construct();
$this->pingdef = new Ping();
$this->agent = new Agent();
$this->servmondef = new ServiceMon();
$this->servicesdef = new ServicesDef();
}
public function pingToday(){
$id = $_POST['id'];
$graphavail = false;
if(isset($_POST['graphavail'])){
$graphavail = true;
}
//get current time
//get past a hour time and plot available data
$starttime = date('Y-m-d').' 00:00:00';
$finishtime = date('Y-m-d G:i:s');
//id get from post method is field priority = table ping monitoring
$id = $_POST['id'];
$this->agent->selectByID($id);
$this->xml->addText('<h3>Agent: '.$this->agent->getDescription().'</h3>','rightcontent',0);
//redundant here.. but how to catch if user directly click the ping today from system summary
//html and controller coupled here. sorry.. i just run out of time
$table ='<table class="subbox"><tr><td rowspan="3" width="60">';
//get traffic light.. translate to an image
$pingmon = HolderFactory::create($id);
$flag = $pingmon->getStatus();
$table.=$this->translateFlagStatus($flag,'bigimage');
$table.='</td><td>Status</td><td>:</td><td>';
$table.=$this->translateFlagStatus($flag,'htmltext');
$table.='</td></tr>';
$table.='<tr><td>';
if($flag=='gray'){
$table.='Last Available is';
}else{
$table.='Available Since';
}
$table.='</td><td>:</td><td>'.$pingmon->getLastAvail().'</td></tr>';
$table.='<tr><td>Current Round Trip Time (RTT)</td><td>:</td><td>';
$table.=$pingmon->getRecent().' ms</td></tr>';
$table.='</table>';
$this->xml->addText($table,'rightcontent',1);
$this->xml->addBreak('rightcontent',2);
$this->pingBox('Today',$starttime,$finishtime,$id,12,$graphavail);
$addedmenu = array('javascript:sndReqPOST(\''.$this->getName().'/lastping\',\'id='.$id.'\')'=>'Latency Last Hour',
'javascript:sndReqPOST(\''.$this->getName().'/pingthismonth\',\'id='.$id.'\')'=>'Latency This Month','break');
if($graphavail){
$addedmenu['javascript:sndReqPOST(\''.$this->getName().'/pingtoday\',\'id='.$id.'\')']='Toogle Availability';
}else{
$addedmenu['javascript:sndReqPOST(\''.$this->getName().'/pingtoday\',\'id='.$id.'&graphavail=true\')']='Toogle Availability';
}
$this->xml->buildSubMenu(array_merge($this->navigator->getSubMenu($this),$addedmenu));
$this->xml->flush();
}
public function show(){
$this->xml->flush();
}
public function index(){
$this->xml->addText(SITENAME.' -systemstat','title',0);
$this->xml->buildSubMenu($this->navigator->getSubMenu($this));
$this->show();
}
//----------------------------------------------------------------------------------------------
//umbrella function that not directly invoked by user goes here
public function pingBox($message,$starttime,$finishtime,$id,$interval,$graphavail){
$plotter = new Plotter();
$array_column='';
$title='';
if($graphavail){
$array_column = array("Checkpoint","Availability (%)");
$title='Table Network Availability';
$headtitle='Availability';
$plotter->setTitle('Network Availability '.$this->agent->getDescription());
}else{
$array_column = array("Checkpoint","RTT (ms)");
$title='Table Network Latency';
$headtitle='Latency';
$plotter->setTitle('Network Latency '.$this->agent->getDescription());
}
$this->xml->addText('<h3>'.$message.' Network '.$headtitle.'</h3>','rightcontent',1);
$plotter->setInterval($interval);
$plotter->setGraphAvail($graphavail);
$plotter->setGraph($id,$starttime,$finishtime);
$subtable = '<table>';
$subtable.='<tr></tr><td>Peak Latency</td><td>:</td><td>'.$plotter->getMaxStat().' ms</td></tr>';
$subtable.='<tr></tr><td>Minimum Latency</td><td>:</td><td>'.$plotter->getMinStat().' ms</td></tr>';
$subtable.='<tr></tr><td>Average Latency</td><td>:</td><td>'.$plotter->getAverageStat().' ms</td></tr>';
$subtable.='<tr></tr><td>Availability ('.$message.')</td><td>:</td><td>';
$subtable.=$plotter->getAvailability().' %</td></tr>';
$subtable.='</table>';
$table = '<table class="subbox">';
$table.='<tr><td><div id="detaildata"></td><td width="20"> </td><td><div id="detailgraph"></div></td></tr>';
$table.='<tr><td colspan="2"></td><td><a name="avail"></a><h3>'.$message.' Summary</h3><div id="availpie"></div>'.$subtable.'</td></tr></table>';
$this->xml->addText($table,'rightcontent',1);
//attach data from graph plotter
$this->xml->addGraph($plotter->attachLine(),'detailgraph',1);
$this->xml->addGraph($plotter->attachPie(),'availpie',1);
$this->xml->addText($plotter->getImageMaps(),'rightcontent',1);
$this->xml->addTable($plotter->getData(),$array_column,$title,null,0,'detaildata',1);
}
//translate priority -> monitoring
//current typeoutput: url, objectholder, objectdefinition
public function translatePriority($priority,$typeoutput){
$monitoring = '';
if($priority[0]=='p'){
$monitoring = 'ping';
}else
if($priority[0]=='s'){
$monitoring ='serv';
}
if($typeoutput=='lasturl'){
$url = 'last'.$monitoring;
}else
if($typeoutput=='todayurl'){
$url = $monitoring.'today';
}
else
if($typeoutput=='todayavailurl'){
$url = $monitoring.'today';
$priority.='&graphavail=true';
}
return 'javascript:sndReqPOST(\''.$this->getName().'/'.$url.'\',\'id='.$priority.'\')';
}
//translate flag status
//type output: image, text, htmlcolor
public function translateFlagStatus($flag,$typeoutput){
if($typeoutput=='bigimage'){
$array = array('green'=>'<img src="gen_picts/trafficUp.gif">','red'=>'<img src="gen_picts/trafficDown.gif">',
'gray'=>'<img src="gen_picts/trafficDown.gif">','yellow'=>'<img src="gen_picts/trafficYellow.gif">');
return $array[$flag];
}else
if($typeoutput=='smallimage'){
$array = array('green'=>'<img src=\'gen_picts/green.jpg\'></img>','red'=>'<img src=\'gen_picts/red.gif\'></img>',
'gray'=>'<img src=\'gen_picts/red.gif\'></img>','yellow'=>'<img src=\'gen_picts/yellow.jpg\'></img>');
return $array[$flag];
}
else
if($typeoutput=='htmltext'){
$array = array('green'=>'Available','red'=>'<text class="red">Critical</text>',
'gray'=>'<text class="red">Down</text>','yellow'=>'Warning');
return $array[$flag];
}
else
if($typeoutput=='plaintext'){
$array = array('green'=>'OK','red'=>'Critical','gray'=>'Down','yellow'=>'Warning');
return $array[$flag];
}
else
if($typeoutput=='htmlcolor'){
$array = array('green'=>'#befff5','yellow'=>'#ff8c8f','gray'=>'#f2f2fc','red'=>'#ff8c8f');
return $array[$flag];
}
}
//return menu for system stat
//get from class navigation
protected function getMenu(){
$this->xml->buildSubMenu($this->navigator->getSubMenu($this));
}
}