Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
// 
// 2011/11/29 - bw - Iterate through component XML branches and add appropriate references 
//                   in component CI tables (network interfaces, disks, etc)


//========================================//
// ipAddresses -> cmdb_ci_network_adapter //
//========================================//

//
// Load the ipAddresses element content into an object
var xmldoc = new XMLDocument(source.u_ipaddresses);

//
// Get a list of nodes to iterate, count numnodes
var nodelist = xmldoc.getNodes("//ipAddresses/*");
var numnodes = nodelist.getLength();

//
// Iterate. For each:
//   * grab the ip
//   * coalesce on network interface table (cmdb_ci == target.sys_id AND ip == ip_address)
//   * insert/update network interface record
var i=0; var ip = ""; var sgr = "";
for (i=0;i<=numnodes;i++) {
    // grab the IP
    ip = nodelist.item(i).getLastChild().getNodeValue();  

    // select & coalesce
    sgr = new GlideRecord("cmdb_ci_network_adapter");
    sgr.addQuery("cmdb_ci", target.sys_id);
    sgr.addQuery("ip_address", ip); // really should be name, not ip.
    sgr.query();
    if ( sgr.getRowCount() == 0 ) {
        // insert
        sgr.initialize();
        sgr.ip_address = ip;
        sgr.cmdb_ci = target.sys_id;
        sid = sgr.insert();
        gs.print("inserted " + ip + " to " + sid);
    } else {
        // update (this assumes only 1 row matched, so next row wins.
        sgr.next();
        sgr.ip_address = ip;
        sid = sgr.update();
        gs.print("inserted " + ip + " to " + sid);
    }   
}
Gliffy
sizeL
nameBigFix Integration
alignleft
version2