X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plekit%2Fphp%2Fcolumns.php;h=cbdb3f39c6d029ca2573e5ae71b4a994f02052ad;hb=46d5ed0785050dace2598da42560be82b3da8fd8;hp=d16b1282062398a5c67fa0ebf4fceb316542b976;hpb=e51a8a29fe84ca8d51e2166ce8603037113f3ce2;p=plewww.git diff --git a/plekit/php/columns.php b/plekit/php/columns.php index d16b128..cbdb3f3 100644 --- a/plekit/php/columns.php +++ b/plekit/php/columns.php @@ -9,75 +9,83 @@ drupal_set_html_head(' class PlekitColumns { var $column_configuration = ""; -var $reference_node = ""; +var $reference_nodes = array(); var $first_time = false; var $all_headers = array(); var $this_table_headers = array(); var $visible_headers = array(); -var $all_columns = array(); var $fix_columns = array(); var $tag_columns = array(); var $extra_columns = array(); +var $comon_live_data = ""; +var $tophat_live_data = ""; +var $ComonData = array(); +var $TopHatData = array(); +var $TopHatAgents = array(); + var $table_ids; var $HopCount = array(); +var $RTT = array(); - function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) { +function PlekitColumns ($column_configuration, $fix_columns, $tag_columns, $extra_columns=NULL, $this_table_headers=NULL) { + if ($column_configuration != NULL) { $this->fix_columns = $fix_columns; $this->tag_columns = $tag_columns; $this->extra_columns = $extra_columns; - //print("

FIX

"); - //print_r($this->fix_columns); - //print("

TAG

"); - //print_r($this->tag_columns); - //print("

EXTRA

"); - //print_r($this->extra_columns); - $this->prepare_headers(); $this->parse_configuration($column_configuration); $this->visible_headers = $this->get_visible(); - - //print("

VISIBLE

"); - //print_r($this->visible_headers); - - $this->all_columns = array_merge($fix_columns, $tag_columns, $extra_columns); + } } /* -INFO +INFO/HEADERS */ function prepare_headers() { foreach ($this->fix_columns as $column) { -$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); +$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'); } -foreach ($this->tag_columns as $column) { +$tmp_headers = array(); -//print("
".$column['header'].":".$column['headerId'].":".$column['tagname']); +if ($this->extra_columns) +foreach ($this->extra_columns as $column) { +$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']); + +} + +if ($this->tag_columns) +foreach ($this->tag_columns as $column) { if ($column['headerId'] != "") $headerId = $column['headerId']; else $headerId = $column['header']; -$this->all_headers[$headerId]=array('header'=>$headerId,'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false); +$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'); } -foreach ($this->extra_columns as $column) { -$this->all_headers[$column['header']]=array('header'=>$column['header'],'type'=>$column['type'],'tagname'=>$column['tagname'],'title'=>$column['title'], 'description'=>$column['title'], 'label'=>$column['header'],'visible'=>false); -} +usort ($tmp_headers, create_function('$col1,$col2','return strcmp($col1["label"],$col2["label"]);')); + +foreach ($tmp_headers as $t) +$this->all_headers[$t['header']] = $t; + +//$this->all_headers = array_merge($this->all_headers, $tmp_headers); + +//print($this->print_headers()); return $this->all_headers; @@ -106,11 +114,11 @@ return ""; function node_tags() { - $fetched_tags = array('node_id'); + $fetched_tags = array('node_id','hostname'); foreach ($this->all_headers as $h) { - if ($h['visible'] == true) + if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc") $fetched_tags[] = $h['tagname']; } @@ -121,9 +129,9 @@ function print_headers() { $headers = ""; - foreach ($this->all_headers as $h) + foreach ($this->all_headers as $l => $h) { - $headers.="
".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible']; + $headers.="
[".$l."]=".$h['header'].":".$h['label'].":".$h['tagname'].":".$h['visible']; } return $headers; } @@ -164,31 +172,43 @@ CONFIGURATION function parse_configuration($column_configuration) { $this->column_configuration = $column_configuration; - //$this->default_configuration = $default_configuration; - $columns_conf = explode("|", $column_configuration); + + foreach ($columns_conf as $c) { $conf = explode(":",$c); - $this->all_headers[$conf[0]]['visible']=true; - //print("

".$conf[0]."should be visible now"); - //print_r($this->all_headers[$conf[0]]); + if ($conf[0] == "default") + continue; - if ($conf[1] == "f") + if (!$this->all_headers[$conf[0]]) continue; + $this->all_headers[$conf[0]]['visible']=true; + + if ($this->all_headers[$conf[0]]['source'] == "comon") + $this->comon_live_data.=",".$this->all_headers[$conf[0]]['tagname']; + + if ($this->all_headers[$conf[0]]['source'] == "tophat") + { + if ($this->all_headers[$conf[0]]['tagname'] == 'hopcount') + { + $this->reference_nodes['hopcount'] = $conf[1]; + //print ("ref node in configuration = ".$conf[1]); + $this->all_headers[$conf[0]]['refnode']=$this->reference_nodes['hopcount']; + } + else if (strpos($this->all_headers[$conf[0]]['tagname'],"agents") === false) + $this->tophat_live_data.=",".$this->all_headers[$conf[0]]['tagname']; + //$threshold = explode(",",$conf[1]); + //$this->all_headers[$conf[0]]['threshold']=$threshold; + } + + //print_r($this->all_headers[$conf[0]]); + +/* else if ($this->inTypeC($conf[0])) { - $this->all_headers[$conf[0]]['duration']= substr($conf[0], strlen($conf[0])-1, strlen($conf[0])); - $threshold = explode(",",$conf[1]); - $this->all_headers[$conf[0]]['threshold']=$threshold; - } - else if ($this->inTypeD($conf[0])) - { - $this->reference_node = $conf[1]; - $this->reference_node = "planetlab-europe-07.ipv6.lip6.fr"; - $this->all_headers[$conf[0]]['refnode']=$this->reference_node; $threshold = explode(",",$conf[1]); $this->all_headers[$conf[0]]['threshold']=$threshold; } @@ -197,12 +217,9 @@ function parse_configuration($column_configuration) { $exclude_list = explode(",",$conf[1]); $this->all_headers[$conf[0]]['exclude_list']=$exclude_list; } - else - { - $threshold = explode(",",$conf[1]); - $this->all_headers[$conf[0]]['threshold']=$threshold; - } +*/ } + } @@ -215,46 +232,253 @@ CELLS */ -function getHopCount($ref_node, $planetlab_nodes) -{ +function convert_data($value, $data_type) { + + //print "converting ".$value." as ".$data_type; + + if ($value == "" || $value == null || $value == "n/a" || $value == "None") + return "n/a"; + + if ($data_type == "string") + return $value; + + if ($data_type == "date") + return date("Y-m-d", $value); + + if ($data_type == "uptime") + return (int)((int) $value / 86400); + + if (is_numeric($value)) + return ((int) ($value * 10))/10; + + return $value; + +} + +function getTopHatAgents() { + + $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest'); + $tophat_api = new TopHatAPI($tophat_auth); + + //print ("Requesting tophat agents..."); + //print_r($r); -$tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest', 'AuthString' => 'guest'); -$tophat_api = new TopHatAPI($tophat_auth); + $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')); -$traceroute = $tophat_api->Get('traceroute', 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', 'hop_count') ); + $result = array(); -$hopcount = array(); + if ($values) foreach ($values as $t) { + //print_r($t); + //print("


"); + $result[$t['hostname']] = ""; + foreach ($t['colocated'] as $ll) { + + if (strpos($result[$t['hostname']]['all'],$ll['platform_name']) === false) { + if ($result[$t['hostname']]['all'] != "") + $result[$t['hostname']]['all'] .= ","; + $result[$t['hostname']]['all'] .= $ll['platform_name']; + } + + if ($ll['platform_name'] == 'SONoMA') { + if (strpos($result[$t['hostname']]['sonoma'],$ll['peer_name']) === false) { + if ($result[$t['hostname']]['sonoma'] != "") + $result[$t['hostname']]['sonoma'] .= ","; + $result[$t['hostname']]['sonoma'] .= $ll['peer_name']; + } + } + + if ($ll['platform_name'] == 'TDMI') { + if (strpos($result[$t['hostname']]['tdmi'],$ll['peer_name']) === false) { + if ($result[$t['hostname']]['tdmi'] != "") + $result[$t['hostname']]['tdmi'] .= ","; + $result[$t['hostname']]['tdmi'] .= $ll['peer_name']; + } + } + } + } + + $this->TopHatAgents = $result; + + //print_r($this->TopHatAgents); + + return $result; +} + +function getTopHatData($data, $planetlab_nodes) { + + $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest'); + $tophat_api = new TopHatAPI($tophat_auth); + + $requested_data = explode(",", $data); + + $r = array ('hostname'); + + foreach ($requested_data as $rd) + if ($rd) $r[] = $rd; + + //print ("Requesting data from TopHat ..."); + //print_r($r); + + $values = $tophat_api->Get('ips', 'latest', array('hostname' => $planetlab_nodes), $r ); + + $result = array(); + + if ($values) foreach ($values as $t) + foreach ($requested_data as $rd) + if ($rd) $result[$t['hostname']][$rd] = $t[$rd]; + + //print_r($result); + + return $result; +} + +function getTopHatRefNodes() { + + $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest'); + $tophat_api = new TopHatAPI($tophat_auth); + + //print "calling tophat for agents"; + + $agents = $tophat_api->Get('agents', 'latest', array('peer_name'=>array('PLC', 'PLE'), 'agent_status'=> 'OK'), array('hostname')); + + //print_r($agents); + + return $agents; + +} + +function getPairwise($ref_node, $planetlab_nodes, $command, $data) { + + $tophat_auth = array( 'AuthMethod' => 'password', 'Username' => 'guest@top-hat.info', 'AuthString' => 'guest'); + $tophat_api = new TopHatAPI($tophat_auth); + + $traceroute = $tophat_api->Get($command, 'latest', array('src_hostname' => $ref_node, 'dst_hostname' => $planetlab_nodes), array('dst_hostname', $data) ); + + print "Got result: ".$traceroute; + + $hopcount = array(); + + if ($traceroute) + { + foreach ($traceroute as $t) + { + $hopcount[$t['dst_hostname']]=$t[$data]; + //print " current: ".$t['dst_hostname'].":".$t['hop_count']; + } + + return $hopcount; + } + else + return ""; +} + +function comon_query_nodes($requested_data) { + + $comon_url = "http://comon.cs.princeton.edu"; + $comon_api_url = "status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name"; + + if (MYSLICE_COMON_URL != "") + $comon_url = MYSLICE_COMON_URL; + + $url = $comon_url."/".$comon_api_url.$requested_data."'"; + + //print ("Retrieving comon data for url ".$url); + + $sPattern = '\', \''; + $sReplace = '|'; + + $str=file_get_contents($url); + + if ($str === false) + return ''; + + $result=preg_replace( $sPattern, $sReplace, $str ); + $sPattern = '/\s+/'; + $sReplace = ';'; + $result=preg_replace( $sPattern, $sReplace, $result ); + + $comon_data = explode(";", $result); + $cl = array(); + $comon_values = array(); + + foreach ($comon_data as $cd) { + $cc = explode("|", $cd); + if ($cc[0] == "name") { + $cl = $cc; + } + $comon_values[$cc[0]] = array(); + $cindex=1; + foreach ($cl as $cltag) { + if ($cltag != "name") + $comon_values[$cc[0]][$cltag] = $cc[$cindex++]; + } + } -if ($traceroute) foreach ($traceroute as $t) -$hopcount[$t['dst_hostname']]=$t['hop_count']; -return $hopcount; + return $comon_values; } //Depending on the columns selected more data might need to be fetched from //external sources -function fetch_data($nodes) { +function fetch_live_data($all_nodes) { -//TopHat pairwise data + //print("

fetching live data

"); + +//comon data + if ($this->comon_live_data != "") { + + //print ("live data to be fetched =".$this->comon_live_data); + $this->ComonData= $this->comon_query_nodes($this->comon_live_data); + //print_r($this->ComonData); + } - if ($this->reference_node != "") +//TopHat per_node data + if ($this->tophat_live_data != "") { $dd = array(); - if ($nodes) foreach ($nodes as $n) + if ($all_nodes) foreach ($all_nodes as $n) $dd[] = $n['hostname']; - if ($potential_nodes) foreach ($potential_nodes as $n) + //print("Calling tophat api for ".$this->tophat_live_data); + $st = time() + microtime(); + $this->TopHatData = $this->getTopHatData($this->tophat_live_data, $dd); + //printf(" (%.2f ms)
", (time() + microtime()-$st)*100); + //print_r($this->TopHatData); + } + +//TopHat pairwise data + + $this->HopCount = ""; + $this->RTT = ""; + + if ($this->reference_nodes != "") + { + //print_r($this->reference_nodes); + + $dd = array(); + + if ($all_nodes) foreach ($all_nodes as $n) $dd[] = $n['hostname']; - print("Calling tophat api for reference node = ".$this->reference_node); $st = time() + microtime(); - $HopCount = $this->getHopCount($this->reference_node, $dd); - printf(" (%.2f ms)
", (time() + microtime()-$st)*100); - //print_r($HopCount); - } + if ($this->headerIsVisible("HC")) + { + print("[NEW] Calling tophat api for HopCount with reference node = ".$this->reference_nodes['hopcount']); + $this->HopCount = $this->getPairwise($this->reference_nodes['hopcount'], $dd, 'traceroute', 'hop_count'); + } + else + if ($this->headerIsVisible("RTT")) + { + print("[NEW] Calling tophat api for RTT with reference node = ".$this->reference_nodes['rtt']); + $this->RTT = $this->getPairwise($this->reference_nodes['rtt'], $dd, 'rtt','rtt'); + } + + //printf(" (%.2f ms)
", (time() + microtime()-$st)*100); + print_r($this->HopCount); + } } @@ -272,6 +496,7 @@ function excludeItems($value, $exclude_list, $hh) { return array($value, array('name'=>$hh, 'display'=>'table-cell')); } + function checkThreshold($value, $threshold, $hh) { if ($value == "") @@ -289,50 +514,123 @@ function checkThreshold($value, $threshold, $hh) { function cells($table, $node) { -$this->fetch_data($node); +//$node_string = ""; + +foreach ($this->all_headers as $h) { -foreach ($this->all_headers as $h) -{ if (!$h['fixed']) { -if ($h['visible'] != "") -{ -if ($this->inTypeC($h['header'])) +if ($h['visible'] != "") { + +/* +if ($this->inTypeB($h['header'])) { - $tagname = $h['tagname']; - $value = $node[$tagname]; + $value = $node[$h['tagname']]; $v = $this->checkThreshold($value, $h['threshold'], $h['header']); $table->cell($v[0],$v[1]); } -else if ($this->inTypeB($h['header'])) +else if ($this->inTypeA($h['header'])) { $value = $node[$h['tagname']]; - $v = $this->checkThreshold($value, $h['threshold'], $h['header']); + $v = $this->excludeItems($value, $h['exclude_list'], $h['header']); $table->cell($v[0],$v[1]); } -else if ($this->inTypeD($h['header'])) +*/ +if ($h['source'] == "comon") { - $value = $this->HopCount[$node['hostname']]; - $v = $this->excludeItems($value, $h['threshold'], $h['header']); - $table->cell($v[0],$v[1]); + //print("
Searching for ".$h['tagname']."at ".$node); + if ($this->ComonData != "") + $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']); + else + $value = "n/a"; + + $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell')); + //$node_string.= "\"".$value."\","; } -else if ($this->inTypeA($h['header'])) +else if ($h['source'] == "tophat") { - $value = $node[$h['tagname']]; - $v = $this->excludeItems($value, $h['exclude_list'], $h['header']); - $table->cell($v[0],$v[1]); + //print("
Searching for ".$h['tagname']."at ".$node); + if ($h['tagname'] == "hopcount") + { + //print "value = ".$this->HopCount[$node['hostname']]; + //$value = "hc"; + if ($this->HopCount != "") + $value = $this->HopCount[$node['hostname']]; + else + $value = "n/a"; + } + else if ($h['tagname'] == "rtt") + { + if ($this->RTT != "") + if ($this->RTT[$node['hostname']] != "") + $value = $this->RTT[$node['hostname']]; + else + $value = "n/a"; + else + $value = "n/a"; + } + else if ($h['tagname'] == "agents") + { + if ($this->TopHatAgents != "") + if ($this->TopHatAgents[$node['hostname']] != "") + $value = $this->TopHatAgents[$node['hostname']]['all']; + else + $value = "n/a"; + else + $value = "n/a"; + } + else if ($h['tagname'] == "agents_tdmi") + { + if ($this->TopHatAgents != "") + if ($this->TopHatAgents[$node['hostname']] != "") + $value = $this->TopHatAgents[$node['hostname']]['tdmi']; + else + $value = "n/a"; + else + $value = "n/a"; + } + else if ($h['tagname'] == "agents_sonoma") + { + if ($this->TopHatAgents != "") + if ($this->TopHatAgents[$node['hostname']] != "") + $value = $this->TopHatAgents[$node['hostname']]['sonoma']; + else + $value = "n/a"; + else + $value = "n/a"; + } + else + { + if ($this->TopHatData != "") + $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']); + else + $value = "n/a"; + } + + $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell')); + //$node_string.= "\"".$value."\","; } else { - $value = $node[$h['tagname']]; + //$value = $node[$h['tagname']]; + $value = $this->convert_data($node[$h['tagname']], $h['type']); $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell')); + //$node_string.= "\"".$value."\","; } } else - $table->cell("??", array('name'=>$h['header'], 'display'=>'none')); + if ($node[$h['tagname']]) + { + $value = $this->convert_data($node[$h['tagname']], $h['type']); + $table->cell($value, array('name'=>$h['header'], 'display'=>'none')); + } + else + $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none')); } } +//return $node_string; + } @@ -345,28 +643,37 @@ HTML function javascript_init() { -print(""); +$refnodes = $this->getTopHatRefNodes(); +//$tophat_agents = $this->getTopHatAgents(); +$ref_nodes = ""; +foreach ($refnodes as $r) +{ + if ($r['hostname'] == $this->reference_nodes['hopcount']) + $selected = "selected=selected"; + else + $selected = ""; + + $ref_nodes = $ref_nodes.""; +} + +print(""); print(""); } - - function quickselect_html() { -//return '

This link uses the onclick event handler.
Open popup

'; - - -$quickselection = ""; $prev_label=""; $optionclass = "out"; foreach ($this->all_headers as $h) { - if ($h['header'] == "hostname") + if ($h['header'] == "hostname" || $h['header'] == "ID") continue; if ($h['fixed']) @@ -375,100 +682,48 @@ foreach ($this->all_headers as $h) $disabled = ""; if ($this->headerIsVisible($h['label'])) - { $optionclass = "in"; - //$selected = "selected=selected"; - } else - { $optionclass = "out"; - //$selected = ""; - } if ($prev_label == $h['label']) continue; $prev_label = $h['label']; + $quickselection.=""; -$quickselection.=""; } - $quickselection.=""; -$quickselection.=" "; return $quickselection; } -function quickselect_popup_html() { - -print('
'); -print ("
"); -print(" "); - -} - function configuration_panel_html($showDescription) { - if ($showDescription) $table_width = 700; else $table_width = 350; -print(""); -print(""); +print("
Add/remove columns
"); +print(""); if ($showDescription) - print(""); + print(""); -print("
Add/remove columnsColumn description and configurationColumn description and configuration
"); +print("
"); - print('
'); + print('
'); print (""); $prev_label=""; $optionclass = "out"; foreach ($this->all_headers as $h) { - if ($h['header'] == "hostname") + if ($h['header'] == "hostname" || $h['header'] == "ID") continue; if ($h['fixed']) @@ -485,7 +740,10 @@ print ("
"); else { $selected = ""; - $fetch = "false"; + if ($h['fetched']) + $fetch = "true"; + else + $fetch = "false"; } print(""); @@ -500,12 +758,14 @@ print ("
"); print (""); } @@ -513,8 +773,8 @@ print ("
+ +
- - - - - +
".$h['label']." ".$h['title']."   
+ + + +
".$h['label']." ".$h['title']."   
"); if ($showDescription) { - print(""); + print(""); } print("");
"); - print("
            
"); + print("