Hi All,
I worked on this as a bit of a demo but thought it would be a good idea to share it with the wider team. the following is a simple integration with the UXI REST API to pull some data and show it on a web page using PHP. this is by no means a complete solution but is enough to get you going with access the API.
If you are wanting to find out more about how to use PHP I would recommend checking out the HowTo at W3 Schools HERE and also the HTML one HERE.
note: I am not going to include all of the HTML as I would expect you to already have a base understanding of how to create an HTML page.
Firstly we will need the PHP code that we will use to call the API and to decide what to do based on certain inputs.
// curl function to get informaiton from the sensor. Input the type of request, the API URL and the data.
function callAPI($method, $url, $data){
$curl = curl_init();
switch ($method){
// GET case
case "GET":
if($data)
$url = sprintf("%s?%s", $url, http_build_quer ($data));
break;
// default to be further implemented
default:
break;
}
// Setup curl options:
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
// configure API-KEY with your API-KEY
'X-API-KEY: xxx-xxx-xxx',
// configure APP-ID with tour APP-ID
'X-APP-ID: xxx-xxx-xxx',
'Content-Type: application/json',
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// EXECUTE:
$result = curl_exec($curl);
if(!$result){
die("Connection Failure");
}
curl_close($curl);
return $result;
}
// function to return an error based on the error code observed. Needs further work to add all error codes.
function printError($error_code){
$error_message = " ";
switch($error_code){
case "WIFI_SSID_MISSING":
$error_message = "A monitored wireless network is no longer detected at this site.";
return $error_message;
case "LOW_EXTERNAL_VOIP_MOS":
$error_message = "Voice application performance has degraded at this site.";
return $error_message;
case "WIFI_ASSOCIATION_FAILED":
$error_message = "The Aruba UXI Sensor was unable to associate to the configured wireless network.";
return $error_message;
case "POWER_OUTAGE":
$error_message = "A power outage has been detected at this location.";
return $error_message;
default:
return;
}
}The above is enough to contact the UXI REST API and get data about what errors are currently active on sensors. The following lets the data be displayed onto a web page. The following is very static and should be built to be more dynamic but is a good starting point to be developed further.
$get_data = callAPI('GET', 'https://api.capenetworks.com/v1/nodes/dg-01247a924fb4'.$user['User']['customer_id'], false);
$response = json_decode($get_data, true);
$nodes = $response['payload']['nodes'];
$site_name = $nodes[0]['name'];
$site_health = $nodes[0]['state'];
echo "<body style='background-color:#2e2e2e'>";
echo '<span style="color:#ffffff;text-align:center;font-size: 20px;font-family: Arial;">The <b>', $site_name, ' </b>is currently in a ';
if($site_health == 'good'){
echo '<span style="color:#86d295;text-align:center;"> healthy</span> state.<br>';
} elseif ($site_health == 'error') {
echo '<span style="color:#f26c60;text-align:center;"> degraded</span> state.<br>';
$er = $nodes[0]['issue_summary'][0]['code'];
$er = printError($er);
echo '  > ', $er, ' Click <a href="https://dashboard.capenetworks.com/circles?hpath=%2Fdg-01247a924fb4" style="text-decoration:none;" target="_blank"><font color="#fc8712">here</font></a> to investigate.<br><br>';
} else {
echo '<span style="color:#f5d45c;text-align:center;"> poor</span> state.<br>';
}With the above, and a bit of extra work around HTML/CSS you can display something like the following on a web page. You could also integrate the data into your own NOC dashboard, and just pull in the information that is relevant to you.

You can find the UXI Swagger UI HERE.
You can check out the live demo at the following - http://ozziewifi.com/uxi_api_demo.php
Thanks !