Rerouting of VM CI's based on Naming Convtention

Karthikeyan03
Tera Contributor

Hello team,

 

As an ITOM developer, I want to reroute the VM CI's based on naming convention, under mid server script includes the following "VMWAREvCenterVMsProbe" creates virtual machines which then goes into cmdb_ci_vmware_instance upon discovery of vCenter's. If possible any virtual machine that begin with "USX" or "USZ we would like to have routed to the cmdb_ci_virtual_desktop table upon discovery, all others would remain in the same table. All CI's that starts with USX or USZ would be automatically moved to cmdb_ci_virtual_desktop upon discovery.

 

 

Should I enable plugin for above requirement?

 

Would you please correct the steps and scripts below, if it is wrong. I am grateful to your response.

 

var vmName = current.name.toString();

if (vmName.startsWith("USX") || vmName.startsWith("USZ")) {

   // Create a new record in cmdb_ci_virtual_desktop table and copy over relevant information

   var newDesktop = new GlideRecord('cmdb_ci_virtual_desktop');

   newDesktop.initialize();

   newDesktop.name = current.name;

   newDesktop.description = current.description;

   newDesktop.os = current.os;

   newDesktop.ip_address = current.ip_address;

   newDesktop.mac_address = current.mac_address;

   // ... copy over other relevant fields

   newDesktop.insert();

  

   }

 

to modify the "process" function in the "VMWarevCenterVMsProbe" script include to include the logic I described earlier:

process: function(vm) {

   // Call the parent process function to do the standard processing

   this.parent.process(vm);

   // Check if the VM name starts with "USX" or "USZ"

   var vmName = vm.name.toString();

   if (vmName.startsWith("USX") || vmName.startsWith("USZ")) {

      // Create a new record in cmdb_ci_virtual_desktop table and copy over relevant information

      var newDesktop = new GlideRecord('cmdb_ci_virtual_desktop');

      newDesktop.initialize();

      newDesktop.name = vm.name;

      newDesktop.description = vm.description;

      newDesktop.os = vm.os;

      newDesktop.ip_address = vm.ip_address;

      newDesktop.mac_address = vm.mac_address;

      // ... copy over other relevant fields

      newDesktop.insert();

     

        }

}

1 ACCEPTED SOLUTION

Hi,

Looks good to me but please test it out in a non-prod environment to be sure.

Regards,
Niklas

View solution in original post

8 REPLIES 8

Niklas Peterson
Mega Sage
Mega Sage

Hi,

Classification in CMDB is done per "type of device". Each classification has it's own table. Meaning CIs in cmdb_ci_vmware_instance are not the same type of CIs as CIs in cmdb_ci_virtual_desktop. You should not  base your classification on the name of the device but something that can properly identify the correct class.

Regards,
Niklas

Hi Niklas,

 

Thank you so much for the swift response and taking the time to acknowledge upon my request.

I agree your point, but the actual problem is that virtual machines CIs are goes into cmdb_ci_vmware_instance (which is a wrong table "cmdb_ci_vmware_instance") instead of "cmdb_ci_virtual_desktop" upon discovery of VCenter's

Hello again,

In what way is the VMware Virtual Machine Instance [cmdb_ci_vmware_instance] the wrong table for Virtual Machine instances?

Here is the reference documentation for VMware discovery and all the classes that is populated.
https://docs.servicenow.com/bundle/utah-it-operations-management/page/product/discovery/reference/r_...

 

The cmdb_ci_virtual_desktop table is for "User's desktop environment (such as icons, wallpaper, windows, folders, toolbars, and widgets) is stored remotely on a server."

https://docs.servicenow.com/bundle/utah-servicenow-platform/page/product/configuration-management/re...

Regards,
Niklas

 

 

Hi Niklas,

 

the correct table is for virtual machine CIs is "cmdb_ci_vmware_instance", the issue is that in the dev environment our virtual desktops which start with USZ & USX also go into that same table, they need to go into the "cmdb_ci_virtual_desktop" table. This has to be fixed.

Would you please provide a solution?

 

Regards

Karthikeyan Palaniyappan