Prizm PHP-Soap examples....

Hi There,

Here’s some PHP/Soap examples for getting things done in Prizm using PHP…
I’m not a programmer by profession so I’m sure someone else will most likely have a much cleaner way of getting things done.
Code is really messy with very little comments … it’s really not for beginners and will most likely require a good understanding of PHP…

First you’ll need to install the PHP/Soap mod…
yum install php-soap.i386 … For redhat and Centos.

Hope this is usefull in some way … I’ll write and post a small script here at a later stage if time allows.

//-- code — //
/// Adding an Element…

$addClient = addElement("$canSerial", “$bamVALUE”, “$SiteName”,"$Location","$Customername");
// Returns an object…

function addElement ($mac, $servicePlanName, $siteName, $siteLocation, $siteContact) {

$USER = “prizmadmin”;
$PASSWORD = “YourPrizmAdminPassword”;
$PRIZMSERVER = “10.230.100.12”;
$SERVICE_LOC = “https://:8443$PRIZMSERVER/prizm/nbi”;
$SERVICE_NS = ‘NetworkIfService’;

$client = new SoapClient(null, array(‘location’ => “$SERVICE_LOC”,
‘uri’ => “$SERVICE_NS”,
‘soap_version’ => SOAP_1_1,
‘login’ => “$USER”,
‘password’ => “$PASSWORD”));

$iNetworkID = (int)6; // This your network ID in prizm… Mine is 6
$authKeys = (string)“00000000000000000000000000000000”;
$vlanProfileName = (string)""; // Add your Vlan profile here , leave it blank otherwise…
$bAddFullManagement = true;

$som = $client->addProvisionedElement($iNetworkID, $mac, $siteName, $siteLocation, $siteContact, $authKeys, $servicePlanName, $vlanProfileName, $bAddFullManagement);
return($som);
}

/// Finding and displaying an element…

getCanInfo($canopySerial);

function getCanInfo($canSerial) {

$USER = “prizmadmin”;
$PASSWORD = “YourPrizmAdminPassword”;
$PRIZMSERVER = “10.230.100.12”;
$SERVICE_LOC = “https://:8443$PRIZMSERVER/prizm/nbi”;
$SERVICE_NS = ‘NetworkIfService’;

$client = new SoapClient(null, array(‘location’ => “$SERVICE_LOC”,
‘uri’ => “$SERVICE_NS”,
‘soap_version’ => SOAP_1_1,
‘login’ => “$USER”,
‘password’ => “$PASSWORD”));

$canSerial = chop($canSerial);
$canSerial = str_replace(’:’, ‘’, $canSerial);

if (preg_match("/0a003e/i", $canSerial)) { // Just making sure it’s an Actual Canopy Serial number being passed.

$sql = “select element_id from nodemgr_element_attribute where mac_address = ‘$canSerial’”;
$sth = ExecQueryPRIZM($sql); // ExecQueryPRIZM is just a function I’ve written to add some sanity …Use your own methods if you like… It’s really of no importance.
$element_id = $sth[0][‘element_id’];
$element = (int)$element_id;
$unitInfo = $client->getPrizmElementById($element);
$unitInfo = (array)$unitInfo; // I find object difficult to work with , so I’m converting it into an array();

foreach($unitInfo as $Key => $Value) {
if (is_array($Value)) {
foreach($Value as $ArrKey => $ArrValue) {
if ($Key == ‘attributeNames’) {
// These are just some of the stats I chose to use … There’s millions of other little things I’ve excluded…
switch ($unitInfo[“attributeNames”][$ArrKey]) {
case “Authentication Occurred “:
case “RF Color Code”:
case “MAC Address”:
case “Management IP”:
case “Software Version : CANOPY”:
case “Bandwidth Service Plan”:
case “Description”:
case “Management State”:
echo $unitInfo[“attributeNames”][$ArrKey].” : “.$unitInfo[“attributeValues”][$ArrKey].”<br />”;
break;
}
} elseif ($Key == ‘statsNames’) {
switch ($unitInfo[“statsNames”][$ArrKey]) {
case “Jitter”:
case “Radio Power Level”:
case “RF Rx Errors”:
case “RF Tx Errors”:
case “Ethernet Status”:
case “Ethernet Rx Errors”:
case “Ethernet Tx Errors”:
echo $unitInfo[“statsNames”][$ArrKey]." : “.$unitInfo[“statsValues”][$ArrKey].”<br />";
break;
}
}
}

}
}
}
}


function ExecQueryPRIZM($query){
// Your Mysql Prizm database settings…
$host = ‘10.230.100.1’;
$user = ‘USERNAME’;
$pass = ‘PASSWORD’;
$dbName = ‘PRIZMDATABASE’;

$link = mysql_connect($host , $user , $pass);
mysql_select_db($dbName, $link);
$res = mysql_query($query,$link) or die(“Error : “.mysql_error().”.<br>SQL :”.$query);

if(is_integer(strpos(strtolower($query),“select”))){
$i=0;
if(mysql_num_rows($res)!=0){
while(mysql_fetch_row($res)) {
$rs[$i] = setmysqlresults($res,$i);
$i++;
}
}
return $rs;

}
}

function setmysqlresults($resultpointer,$row = 0) {
$i=0;
$n=mysql_num_fields($resultpointer);
while($i<$n) {
$fieldname = mysql_field_name($resultpointer,$i);
$fieldresult = mysql_result($resultpointer,$row,$fieldname);
$hash[$fieldname] = $fieldresult;
$i++;
}
return $hash;
}