Identifying the Correct Device Status in a RISPort Response

Author
William Bell
Vice President, Solutions and Products

A couple of weeks ago I started discussing the RISPort API and how it compares to devicelistx.asp (from my point of view, at least). So far I have found this API to be pretty handy and relatively quick.  Definitely faster than devicelistx.asp with larger data sets.  There are various lessons I am learning as I work through updating my various tools.  One of these valuable lessons is that it is very possible that the RIS response will list a device you are looking for more than once.

To understand “why”, we have to look at the structure of the response.  A snippet of an example response:

For our discussion, the key XML nodes are the item nodes, the Status node, and the TimeStamp node.  As you can see there are various item nodes (confusing I know) and they are differentiated by the attribute “type”.  The first node type of interest is “ns1:CmNode”.  As seen in the example, every CUCM node is included in the response.  In our example there is the CUCM node with the IP address of 10.10.10.7 and a second one with the IP address of 10.10.10.8.

Both nodes report status for the same IP phone (SEP001EF72A48C5).  Looking at the Status node you can see on 10.10.10.7 the phone is registered and on 10.10.10.8 the phone is unregistered.  In this example, we forced a failure on the 10.10.10.7 server (so phones failed over to 10.10.10.8) and then we resolved the failure (so that phones failed back).  So, the why is easy.  But which report should be trusted?

The answer is both are valid and you have to determine the latest news by reviewing the TimeStamp field.  Obviously doing this check manually for a potential group of a few dozen (much less a few thousand) phones is  not how one should spend their day.  I came across this while testing some tools, so it is onlyfair to show how one could do it programatically.

The first step is to submit a properly formatted RIS request and then grab the resulting XML response stream from the CUCM first node (publisher).  I use a windows ActiveXObject called “MSXML2.DOMDocument.4.0” as my XML document object holder.  You can find out more on this object here. Using this object I can use XSL structured queries to find my device and walk through the various child nodes.  The following is a snippet of code used to get the info I need from the RIS response:

/*at this point we have already retrieved the node list and are searching for a specific IP phone*/
var nodelist = xmldom.selectNodes("//CmDevices/item[Name="" + devname.toUpperCase() + ""]");
var mytimestamp=0;
var mystatus="";
for(var row=0;row
{  //loop through nodelist
    var child = nodelist.item(row);
    var tmpstatus = child.selectSingleNode("Status").text;
    var tmptimestamp = Number(child.selectSingleNode("TimeStamp").text);
    var myipaddr = child.selectSingleNode("IpAddress").text;
    if (nodelist.length > 1 && row < nodelist.length)
    {  //we have a record with more than one result and we still have not reached the end of the results
        if (mytimestamp != 0)
        {  //we have a previous entry for this device
            if (tmptimestamp <= mytimestamp)
                { //we need to check further
                     if (tmptimestamp == mytimestamp)
                      {
                        if(mystatus == "Registered")
                        {  //if timestamps are identical and the previous child node was registered
                           // we will choose the record that is registered
                             tmpstatus = mystatus;
                             tmptimestamp = mytimestamp;
                        }
                       }else{
                              tmptimestamp = mytimestamp;
                              tmpstatus = mystatus;
                       }
                  }
            }
       }
       mystatus = tmpstatus;
       mytimestamp = tmptimestamp;
}  //end for loop; looping through nodelist
/*keep on truckin through to the next IP phone controller by an outer for loop*/

In the example, xmldom is my XML document that I have the RIS response stored from the CUCM cluster.  The program iteslf has the task of checking a list of 200 devices and determine that current status of each one.  We have an other loop (not shown) that will go through each device sequentially.  In the code shown, we are running a query against the XML data to find all nodes that match the device we care about.  We do this by searching for the “Name” attribute (e.g. Name=”SEP001EF72A48C5″).  Using the example XML we showed earlier, this would return two child nodes (one reported by the 10.10.10.7 CUCM server and the other reported by the 10.10.10.8 server).

So, we may have 1 or more child nodes to deal with.  To make sure we get the latest data (that is all we care about for the moment) we have to grab the status and timestamp information. For the first child node, we simply set the “mystatus” and “mytimestamp” variables.  On the second pass through, we actually have to check the next child node’s time stamp.  If the second time stamp is greater, we just accept that as the most valid record.  If the second time stamp is lesser, then we discard the current node’s data as it is not the most recent.

If the second time stamp is equal to the current “latest time” (mytimestamp) we check the “latest status” (mystatus) to see if we have a Registered record already.  If so, we prefer to keep that record.  This isn’t a common occurence but it can happen.

One response to “Identifying the Correct Device Status in a RISPort Response

  1. Hello,

    I’ve been reading over a lot of documents and I’ve been trying to figure out what is the best tool to use for:
    1. Locating a users phone/username/etc
    2. displaying their missed call information on a webpage
    3. having them click the link and it dials the number of the missed call on their phone.

    What I have working:
    -AXL wsdl is working and executing queries from C#.net 3.5 on AXL namespace 7.0
    -I have been able to locate user information by executing queries
    -Web Dialer is executing calls

    I really want to know if this is possible with AXL+web dialer, or if I will need to work with TAPI to get the missed call information?
    Is there just one tool I can use to get all of this done and I’ve just been over looking it in all the documentation?

    Thanks,

    -1ze

Leave a Reply