VMware discovery CI "Install_status" and "state"<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Sometimes, it is observed that even the Vmware team has deleted the VMs from the Vcenter and still the Discovery does not change the install_status of the specific VM CI, this article will provide the details of VMware discovery CI "Install_status" & "state". The Vcenter Discovery goes through Probes and Sensors (Though Discovery of VMWare is triggered through the CMP portal) In the "VMWarevCenterVMsProbe" MID Script Include, we fetch the power state of each VM (discovered in the current run). if state == 'poweredOn' then state is considered to be 'on'if state == 'poweredOff' then state is considered to be 'off'if different than above 2 states then the state is considered to be 'paused' If VMs exists in the subsequent runs then the State of the VM is always updated based on the VM's state retrieved from the object path "runtime.powerstate" via Object Browser available in VMWare Console Refer below screenshot during the vCenter discovery, In the "VCenterDatacentersSensor" Script include, we look for the VMs that belongs to same vCenter but not found in the current discovery run then we mark those as stale and update their install_status ("Status") to Retired ("7"). // Mark stale VMs as 'retired'gr = new GlideMultipleUpdate('cmdb_ci_vmware_instance');gr.addQuery('vcenter_ref', vCenterSysId);gr.addQuery('object_id', 'NOT IN', vmObjIds);gr.setValue('install_status', '7');gr.setValue('state', 'terminated');gr.execute(); In the "VCenterVMsSensor" Script Include, we update the install_status ("Status") to Installed ("1") if at all if it is marked as stale i.e., install_status=7. function preWriteVm(obj, gr) {// '7' = retired, '1' == installed// When a VM becomes stale we set the status to retired. We don't want// to change the status unless we previously set it. The best we can do// is to check to see if the status is what we would have set it to.if (gr.install_status + '' == '7')gr.install_status = '1'; In the "VMware Virtual Machine Instance" (cmdb_ci_vmware_instance) table, the defaults are set to "1" (Installed) for the "install_status" (Status) and "Operational status" (operational_status) but nothing is set for the "state".If VMs, found in one run, aren't found in the subsequent runs then first thing is they are updated as "stale" in the "cmdb_health_result" table and once they're updated as stale then the install_status ("status") field is updated as "Retired" while the state is left as it is in the previous run.SCRIPT INCLUDE: "VCenterDatacentersSensor", METHOD: "updateStaleness", LINE: 354Not only VMWare but most of the CIs, once discovered they aren't deleted instead their status is managed by marking them as "Retired" Additional Information. Please check the link below regarding the CI's staleness in CMDB. Thanks.https://docs.servicenow.com/bundle/orlando-it-operations-management/page/product/discovery/concept/c_DiscoveryForVMwareVCenter.htmlBelow code is what is run to update the "install_status" (Status) field alone but not any other field(s) SCRIPT INCLUDE: "VCenterDatacentersSensor", METHOD: "updateStaleness", LINE: 354 // Mark stale VMs as 'retired'gr = new GlideMultipleUpdate('cmdb_ci_vmware_instance');gr.addQuery('vcenter_ref', vCenterSysId);gr.addQuery('object_id', 'NOT IN', vmObjIds);gr.setValue('install_status', '7');gr.execute(); If wanted the "state" field also to be updated then you can just modify the query as below: // Mark stale VMs as 'retired'gr = new GlideMultipleUpdate('cmdb_ci_vmware_instance');gr.addQuery('vcenter_ref', vCenterSysId);gr.addQuery('object_id', 'NOT IN', vmObjIds);gr.setValue('install_status', '7');gr.setValue('state', 'terminated');gr.execute();