3 require_once 'tophat_api.php';
6 <script type="text/javascript" src="/plekit/table/columns.js"></script>
11 var $column_configuration = "";
12 var $reference_nodes = array();
13 var $first_time = false;
15 var $all_headers = array();
16 var $this_table_headers = array();
17 var $visible_headers = array();
19 var $fix_columns = array();
20 var $tag_columns = array();
21 var $extra_columns = array();
23 var $comon_live_data = "";
24 var $tophat_live_data = "";
25 var $ComonData = array();
26 var $TopHatData = array();
27 var $TopHatAgents = array();
31 var $HopCount = array();
34 function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) {
36 if ($column_configuration != NULL) {
37 $this->fix_columns = $fix_columns;
38 $this->tag_columns = $tag_columns;
39 $this->extra_columns = $extra_columns;
41 $this->prepare_headers();
42 $this->parse_configuration($column_configuration);
44 $this->visible_headers = $this->get_visible();
56 function prepare_headers() {
58 foreach ($this->fix_columns as $column) {
59 $this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fixed'=>true, 'visible'=>false, 'source'=>'myplc');
62 $tmp_headers = array();
64 if ($this->extra_columns)
65 foreach ($this->extra_columns as $column) {
66 $tmp_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'], 'fetched'=>$column['fetched'], 'visible'=>false, 'source'=>$column['source']);
70 if ($this->tag_columns)
71 foreach ($this->tag_columns as $column) {
73 if ($column['headerId'] != "")
74 $headerId = $column['headerId'];
76 $headerId = $column['header'];
78 $tmp_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false, 'source'=>'myplc');
81 usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);'));
83 foreach ($tmp_headers as $t)
84 $this->all_headers[$t['header']] = $t;
86 //$this->all_headers = array_merge($this->all_headers, $tmp_headers);
88 //print($this->print_headers());
90 return $this->all_headers;
95 function get_headers() {
97 return $this->all_headers;
101 function get_selected_period($label) {
103 if ($this->all_headers[$label."w"]['visible'])
105 else if ($this->all_headers[$label."m"]['visible'])
107 else if ($this->all_headers[$label."y"]['visible'])
109 else if ($this->all_headers[$label]['visible'])
115 function node_tags() {
117 $fetched_tags = array('node_id','hostname');
119 foreach ($this->all_headers as $h)
121 if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
122 $fetched_tags[] = $h['tagname'];
125 return $fetched_tags;
128 function print_headers() {
132 foreach ($this->all_headers as $l => $h)
134 $headers.="<br>[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible'];
139 function get_visible() {
141 $visibleHeaders = array();
143 foreach ($this->all_headers as $h)
145 if ($h['visible'] == true)
146 $visibleHeaders[] = $h['header'];
148 return $visibleHeaders;
151 function headerIsVisible($header_name) {
153 $headersToShow = $this->visible_headers;
155 if (in_array($header_name, $headersToShow))
158 if ($this->inTypeC($header_name."w"))
159 return (in_array($header_name."w", $headersToShow) || in_array($header_name."m", $headersToShow) || in_array($header_name."y", $headersToShow));
172 function parse_configuration($column_configuration) {
174 $this->column_configuration = $column_configuration;
175 $columns_conf = explode("|", $column_configuration);
178 foreach ($columns_conf as $c)
180 $conf = explode(":",$c);
182 if ($conf[0] == "default")
185 if (!$this->all_headers[$conf[0]])
188 $this->all_headers[$conf[0]]['visible']=true;
190 if ($this->all_headers[$conf[0]]['source'] == "comon")
191 $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
193 if ($this->all_headers[$conf[0]]['source'] == "tophat")
194 $this->tophat_live_data.=",".$this->all_headers[$conf[0]]['tagname'];
209 function convert_data($value, $data_type) {
211 //print "converting ".$value." as ".$data_type;
213 if ($value == "" || $value == null || $value == "n/a" || $value == "None")
216 if ($data_type == "string")
219 if ($data_type == "date")
220 return date("Y-m-d", $value);
222 if ($data_type == "uptime")
223 return (int)((int) $value / 86400);
225 if (is_numeric($value))
226 return ((int) ($value * 10))/10;
232 function getTopHatAgents() {
234 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
235 $tophat_api = new TopHatAPI($tophat_auth);
237 //print ("Requesting tophat agents...");
240 $values = $tophat_api->Get('agents', 'latest', array('colocated.platform_name' => array('SONoMA', 'DIMES', 'ETOMIC', 'TDMI'), 'platform_name'=> 'TDMI'), array('hostname', 'colocated.peer_name', 'colocated.platform_name'));
244 if ($values) foreach ($values as $t) {
247 $result[$t['hostname']] = "";
248 foreach ($t['colocated'] as $ll) {
250 if (strpos($result[$t['hostname']]['all'],$ll['platform_name']) === false) {
251 if ($result[$t['hostname']]['all'] != "")
252 $result[$t['hostname']]['all'] .= ",";
253 $result[$t['hostname']]['all'] .= $ll['platform_name'];
256 if ($ll['platform_name'] == 'SONoMA') {
257 if (strpos($result[$t['hostname']]['sonoma'],$ll['peer_name']) === false) {
258 if ($result[$t['hostname']]['sonoma'] != "")
259 $result[$t['hostname']]['sonoma'] .= ",";
260 $result[$t['hostname']]['sonoma'] .= $ll['peer_name'];
264 if ($ll['platform_name'] == 'TDMI') {
265 if (strpos($result[$t['hostname']]['tdmi'],$ll['peer_name']) === false) {
266 if ($result[$t['hostname']]['tdmi'] != "")
267 $result[$t['hostname']]['tdmi'] .= ",";
268 $result[$t['hostname']]['tdmi'] .= $ll['peer_name'];
274 $this->TopHatAgents = $result;
276 //print_r($this->TopHatAgents);
281 function getTopHatData($data, $planetlab_nodes) {
283 $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest');
284 $tophat_api = new TopHatAPI($tophat_auth);
286 $requested_data = explode(",", $data);
288 $r = array ('hostname');
290 foreach ($requested_data as $rd)
293 //print ("Requesting data from TopHat ...");
296 $values = $tophat_api->Get('ips', 'latest', array('hostname' => $planetlab_nodes), $r );
300 if ($values) foreach ($values as $t)
301 foreach ($requested_data as $rd)
302 if ($rd) $result[$t['hostname']][$rd] = $t[$rd];
310 function comon_query_nodes($requested_data) {
312 $comon_url = "http://comon.cs.princeton.edu";
313 $comon_api_url = "status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name";
315 if (MYSLICE_COMON_URL != "")
316 $comon_url = MYSLICE_COMON_URL;
318 $url = $comon_url."/".$comon_api_url.$requested_data."'";
320 //print ("Retrieving comon data for url ".$url);
322 $sPattern = '\', \'';
325 $str=@file_get_contents($url);
330 $result=preg_replace( $sPattern, $sReplace, $str );
333 $result=preg_replace( $sPattern, $sReplace, $result );
335 $comon_data = explode(";", $result);
337 $comon_values = array();
339 foreach ($comon_data as $cd) {
340 $cc = explode("|", $cd);
341 if ($cc[0] == "name") {
344 $comon_values[$cc[0]] = array();
346 foreach ($cl as $cltag) {
347 if ($cltag != "name")
348 $comon_values[$cc[0]][$cltag] = $cc[$cindex++];
352 return $comon_values;
356 //Depending on the columns selected more data might need to be fetched from
359 function fetch_live_data($all_nodes) {
361 //print("<p>fetching live data<p>");
364 if ($this->comon_live_data != "") {
366 //print ("live data to be fetched =".$this->comon_live_data);
367 $this->ComonData= $this->comon_query_nodes($this->comon_live_data);
368 //print_r($this->ComonData);
371 //TopHat per_node data
372 if ($this->tophat_live_data != "")
376 if ($all_nodes) foreach ($all_nodes as $n)
377 $dd[] = $n['hostname'];
379 //print("Calling tophat api for ".$this->tophat_live_data);
380 $st = time() + microtime();
381 $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd);
382 //printf(" (%.2f ms)<br/>", (time() + microtime()-$st)*100);
383 //print_r($this->TopHatData);
389 function cells($table, $node) {
393 foreach ($this->all_headers as $h) {
397 if ($h['visible'] != "") {
399 if ($h['source'] == "comon")
401 //print("<br>Searching for ".$h['tagname']."at ".$node);
402 if ($this->ComonData != "")
403 $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
407 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
408 //$node_string.= "\"".$value."\",";
410 else if ($h['source'] == "tophat")
412 if ($this->TopHatData != "")
413 $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
417 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
418 //$node_string.= "\"".$value."\",";
422 //$value = $node[$h['tagname']];
423 $value = $this->convert_data($node[$h['tagname']], $h['type']);
424 $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
425 //$node_string.= "\"".$value."\",";
429 if ($node[$h['tagname']])
431 $value = $this->convert_data($node[$h['tagname']], $h['type']);
432 $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
435 $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
439 //return $node_string;
451 function javascript_init() {
453 print("<script type='text/javascript'>");
454 print("highlightOption('AU');");
455 print("overrideTitles();");
460 function quickselect_html() {
462 $quickselection = "<select id='quicklist' onChange=changeSelectStatus(this.value)><option value='0'>Short column descriptions and quick add/remove</option>";
464 $optionclass = "out";
465 foreach ($this->all_headers as $h)
467 if ($h['header'] == "hostname" || $h['header'] == "ID")
471 $disabled = "disabled=true";
475 if ($this->headerIsVisible($h['label']))
478 $optionclass = "out";
480 if ($prev_label == $h['label'])
483 $prev_label = $h['label'];
485 $quickselection.="<option id='option'".$h['label']." class='".$optionclass."' value='".$h['label']."'><span class='bold'>".$h['label']."</span>: ".$h['title']."</option>";
489 $quickselection.="</select>";
491 return $quickselection;
496 function configuration_panel_html($showDescription) {
498 if ($showDescription)
503 print("<table class='center' width='".$table_width."px'>");
504 print("<tr><th class='top'>Add/remove columns</th>");
506 if ($showDescription)
507 print("<th class='top'>Column description and configuration</th>");
509 print("</tr><tr><td class='top' width='300px'>");
511 print('<div id="scrolldiv">');
514 $optionclass = "out";
515 foreach ($this->all_headers as $h)
517 if ($h['header'] == "hostname" || $h['header'] == "ID")
521 $disabled = "disabled=true";
525 if ($this->headerIsVisible($h['label']))
527 $selected = "checked=true";
529 //print("header ".$h['label']." checked!");
540 print("<input type='hidden' id='tagname".$h['header']."' value='".$h['tagname']."'></input>");
542 if ($prev_label == $h['label'])
545 $prev_label = $h['label'];
546 $period = $this->get_selected_period($h['label']);
549 <input type='hidden' id='fetched".$h['label']."' value=',".$period.",".$fetch."'></input>
550 <input type='hidden' id='period".$h['label']."' value='".$period."'></input>
551 <input type='hidden' id='type".$h['label']."' value='".$h['type']."'></input>
552 <input type='hidden' id='source".$h['label']."' value='".$h['source']."'></input>
553 <div id='".$h['label']."' name='columnlist' class='".$optionclass."' onclick='highlightOption(this.id)'>
554 <table class='columnlist' id='table".$h['label']."'><tr>
555 <td class='header'><span class='header'>".$h['label']."</span></td>
556 <td align=left> <span class='short' id ='htitle".$h['label']."'>".$h['title']."</span> </td>
557 <td class='smallright'> <span class='short' id ='loading".$h['label']."'></span> </td>
558 <td class='smallright'><input id='check".$h['label']."' name='".$h['tagname']."' type='checkbox' ".$selected." ".$disabled." autocomplete='off' value='".$h['label']."' onclick='changeCheckStatus(this.id)'></input></td>
559 </tr></table></div></td></tr>");
562 print("</table> </div></td>");
564 if ($showDescription)
566 print("<td class='top' width='400px'>");
567 print("<div id='selectdescr'> </div></td>");
572 if ($showDescription)
575 print(" </tr> </table>");
580 function column_filter () {
584 Highlight <select onChange="filterByType(this.value)">
585 <option value="none">None</option>
586 <option value="capabilities">Capabilities</option>
587 <option value="statistics">Statistics</option>
588 <option value="network">Network</option>
589 <option value="pairwise">Pairwise</option>
590 <option value="other">Other</option>
597 function column_html ($colHeader, $colName, $colId, $fulldesc, $visible) {
600 $display = 'display:table-cell';
602 $display = 'color:red;display:none';
605 <th class='sample plekit_table' name='confheader".$colHeader."' id='testid' style='".$display."'>
606 <div id=\"".$colId."\" onclick=\"showDescription('".$colHeader."')\" onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div>
611 function column_fix_html ($colHeader, $colName, $colId) {
613 $display = 'display:table-cell';
615 $res="<th name='confheader".$colHeader."' class='fix plekit_table' style='$display'>";
616 $res.= "<div id='$colId' onmouseover=\"showDescription('".$colHeader."')\">$colHeader</div></th>";
630 function inTypeA($header_name) {
631 $typeA = array('ST','SN','RES','OS','NRR','NTP','NSR','NSF','NDS','NTH','NEC','LRN','LCY','LPR','LCN','LAT','LON','IP','ASN','AST');
632 return in_array($header_name, $typeA);
636 function inTypeB($header_name) {
637 $typeB = array('BW','DS','MS','CC','CR','AS','DU','CN');
638 return in_array($header_name, $typeB);
642 function inTypeC($header_name) {
643 $typeC = array('Rw','Rm','Ry','Lw','Lm','Ly','Sw','Sm','Sy','CFw','CFm','CFy','BUw','BUm','BUy','MUw','MUm','MUy','SSHw','SSHm','SSHy');
644 return in_array($header_name, $typeC);
648 function inTypeD($header_name) {
649 $typeD = array('HC');
650 return in_array($header_name, $typeD);
654 function removeDuration($header)
656 if ($this->inTypeC($header))
657 return substr($header, 0, strlen($header)-1);