children() as $response){
if($response->errorcode == 0) {
$key = $response->node->name;
$nodestat_arr["$key"] = $response->node->data->contents;
}
}
#print_r($nodestat_arr);
if($type == "table") {
#output the data into One table
echo "
";
echo <<
Node Name | Status |
TH00;
echo "";
foreach($nodestat_arr as $k => $v) {
echo "$k | $v |
";
}
echo "
";
}else if($type == "json") {
#Currently, we only return the numbers of nodes in different status
$num_arr = array( array(label => "Operating", data => 0), array( label => "Running", data => 0), array(label => "Not Activated", data => 0), array(label => "Open Firmware", data => 0));
foreach ($nodestat_arr as $k => $v) {
switch ($v) {
case "Operating":
$num_arr[0][data]++;
break;
case "Running":
$num_arr[1][data]++;
break;
case "Not Activated":
$num_arr[2][data]++;
break;
case "Open Firmware":
$num_arr[3][data]++;
break;
}
}
#convert the array to JSON-type
#print_r($num_arr);
echo json_encode($num_arr);
return json_encode($num_arr);
}
?>