Merge CMDB Data into the Nutanix VM Data

Approach:

I decided on using IP Addresses to match the exported server CMDB data with the VM data collected from Nutanix Prism Central. The first step is to add CMDB properties to the existing objects that hold the VM data.

# Start add CMDB properties to the NTNX data objects
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_FQDN' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'InCMDB' -Value 'N'
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDBStatus' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_First_Discovered' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_Last_Discovered' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_Model' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_Maker' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_Site' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_sys_class_name' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_cpu_count' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_cpu_core_count' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_RecordCount' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_OS' -Value ''
$ntnxreport | Add-Member -MemberType NoteProperty -name 'CMDB_IP_Address' -Value ''
# End add CMDB properties to the NTNX data objects

The Nutanix VM data can have one or more IPv4 address in the ‘IP Address(es)’ property. The exported ServiceNow server CI has only one IPv4 address in the ‘ip_address’ property. So I’ll create a regular expression for ‘ip_address’ and check for a match anywhere in ‘IP Address(es)’.

# Start Merge server CMDB data into Nutanix VM data
ForEach($srv in $ntnxReport) {
   $srvip = $null
   $srvip = $($srv.'IP Address(es)')
   if($null -ne $srvip) {
      ForEach($r in $CMDBServers) {
         $ipstring = ''
	 $ipString = $($r.ip_address)
	 $carray = @()
	 $ipregex = $null
	 if( $ipstring -ne '') {
            $carray = $ipstring.ToCharArray()
	    ForEach($c in $carray){
	       $ipregex += "[$c]"	
	    }
            if( ($ipregex.length -gt 1) -and ($srvip -match $ipregex)) {
	       $srv.CMDB_FQDN = $r.fqdn
	       $srv.InCMDB = 'Y'
	       $srv.CMDBStatus = $r.CMDBStatus
	       $srv.CMDB_First_Discovered = $r.first_discovered
	       $srv.CMDB_Last_Discovered = $r.last_discovered
	       $srv.CMDB_Model = $r.model
	       $srv.CMDB_Maker = $r.Maker
	       $srv.CMDB_Site = $r.Site
	       $srv.CMDB_CPU_Count = $r.cpu_count
	       $srv.CMDB_CPU_Core_Count = $r.cpu_core_count
	       $srv.CMDB_OS = $r.os
	       $srv.CMDB_RecordCount = $r.recordCount
	       $srv.CMDB_sys_class_name = $r.sys_class_name
	    }
         }
      }
   }
}
# End Merge server CMDB data into Nutanix VM data