Virtual Machine in the CMDB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 09:59 AM
Hi All,
How to Identify the Virtual Machine in the CMDB for Auto discovery.
I've created the script to identify Virtual machine for some server.
Please help me to color code or identify the all Physical (In green color) and Virtual (Light green Color).
Thanks,
Santosh
- Labels:
-
Discovery
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 10:32 AM
There is no need to write your own script to identify virtual servers. SNC has a business rule OOB on the computer table that does this. It will flag the same attribute you are using if the record meets the conditions. If you want to check it out, look for the "Virtual Computer Check" BR on the computer table.
As to the color coding, where do you want this? If it's for a report in SN, you can simply filter/group by "virtual." You can do the same thing to the list view of records in SN. If it is for a spreadsheet outside of SN, I would just use standard excel color formatting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 12:06 PM
Hi Prdelong,
Thanks for your quick responce.
I've activated the Business Rule "Virtual Computer Check" and then rerun the discovery for HPUX or Unix server.
Also, discovery gets the usual server data for HPUX or Unix virtual machine but does not set the "Is Virtual" [virtual] field.
Thanks,
Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2014 12:39 PM
Can you post a screenshot of a few example records? That particular business rule checks for VMware, solaris zones, and a few other types of VMs IIRC by serial number. What do the serial numbers and model ID for those say?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2014 01:42 PM
Hi,
Please have a look the below screen shot:
Also, I've amended the Business Rule (highlighted in yellow color):
/*
*
Maybe move this to an event on device complete if this ends up being a
perforamnce issue.
* The reason
is this BR would run as long there's data in serial_number or correlation_id.
*/
(function(){
var g_disco_functions = new DiscoveryFunctions();
var
fVMGr = current;
var fInstanceGr;
var fHypervisorGr;
startVirtualComputerCheck();
function
startVirtualComputerCheck() {
// Putting the easier ones to identify at the front so we don't spend extra
effort looking up the others
if (isSolarisZone())
handleSolariZone();
else if (isVMWare())
handleVMWare();
else if(isHPUX())
handleHPUX();
else if (isHyperV())
handleHyperV();
else
return;
current.virtual
= true;
//
By this point we know if we have found a vm instance record
if (JSUtil.nil(fInstanceGr))
return;
// We DO have an instance record, so let's create the "instantiates" relationship between VM and Instance
g_disco_functions.createRelationshipIfNotExists(fVMGr, fInstanceGr,
"Instantiates::Instantiated by");
//
Now, let's find the hypervisor...
fHypervisorGr = findVMWareByImage(fInstanceGr);
if (JSUtil.nil(fHypervisorGr))
return;
// The HyperVisor DOES exist, so let's create the "virtualized by" 'relationship between VM and Hypervisor
// However,
before we do that, let's see if VM already has relationship with another
Hypervisor and if so, we
// need to migrate the relationship.
//
*note: This shouldn't happen if the relationship was properly managed from the
VM instance side.
//
But we'll do it just in case...
reconcileRelationVMtoHyperVisor();
}
function
isSolarisZone() {
if (fVMGr.sys_class_name != "cmdb_ci_solaris_server")
return false;
if
(!fVMGr.correlation_id.hasValue())
return false;
if
(!fVMGr.correlation_id.startsWith("zone-"))
return
false;
return true;
}
function
isVMWare(){
if (!fVMGr.serial_number.hasValue())
return false;
if
(!fVMGr.serial_number.toLowerCase().startsWith("vmware-"))
return false;
return
true;
}
function isHPUX(){
var model_name=fVMGr.model_id.name;
gs.log(model_name,"isHPUX");
if (fVMGr.sys_class_name != "cmdb_ci_hpux_server")
return false;
if
(!fVMGr.model_id.hasValue())
return false;
if
(model_name.indexOf("Integrity Virtual Machine")==0)
return false;
gs.log(model_name,"isHPUX");
return true;
}
function isHyperV() {
var serialNumber = fVMGr.serial_number;
if (!serialNumber.hasValue())
return false;
var
instGr = new GlideRecord("cmdb_ci_hyper_v_instance");
var qc = instGr.addQuery("baseboard_serial", serialNumber);
qc.addOrCondition("bios_serial", serialNumber);
qc.addOrCondition("chassis_serial", serialNumber);
instGr.query();
if (!instGr.next())
return
false;
fInstanceGr
= instGr;
return true;
}
function handleSolariZone() {
var matchingId = fVMGr.correlation_id.substring(5);
var gr = new GlideRecord('cmdb_ci_solaris_instance');
gr.addQuery('correlation_id', matchingId);
gr.query();
if (gr.next())
fInstanceGr =
gr;
}
function
handleVMWare() {
var
matchingId = fVMGr.serial_number.substring(7);
var
gr = new GlideRecord('cmdb_ci_vmware_instance');
gr.addQuery('correlation_id', matchingId);
gr.query();
if (gr.next())
fInstanceGr = gr;
}
function handleHPUX(){
var matchingId = fVMGr.serial_number.substring(7);
gs.log(matchingId,"handleHPUX");
var
gr = new GlideRecord('cmdb_ci_hpux_server');
gr.addQuery('correlation_id', matchingId);
gr.query();
if (gr.next())
fInstanceGr = gr;
}
function handleHyperV() {
matchingId = fVMGr.serial_number+'';
// The fInstanceGr is already handled in isHyperV() method. Just so that we
don't waste another query.
}
function
findVMWareByImage(instGr) {
var gr = new GlideRecord("cmdb_rel_ci");
gr.query("parent", instGr.sys_id);
gr.query("type", g_disco_functions.findCIRelationshipType("cmdb_rel_type",
"Registered on::Has registered"));
gr.query();
if (gr.next())
return gr.child;
return;
}
function
reconcileRelationVMtoHyperVisor() {
var gr = new GlideRecord('cmdb_rel_ci');
gr.query('parent', fVMGr.sys_id);
gr.query('type', g_disco_functions.findCIRelationshipType("cmdb_rel_type",
"Virtualized by::Virtualizes"));
gr.query();
// If we found nothing, then let's simply create the relationship between VM
and Hypervisor
if (gr.getRowCount() == 0) {
g_disco_functions.createRelationshipIfNotExists(fVMGr,
fHypervisorGr, "Virtualized
by::Virtualizes");
return;
}
//
We found existng relationship(s) between VM and HyperVisor(s). Theoretically
there should be only 1
// If we did find multiple, then We want to just correct the first relationship
and then delete the rest
var done = false;
while (gr.next()) {
if (done == true) {
gr.deleteRecord();
continue;
}
//
If they don't match, let's re-point the child to the correct hypervisor
if ((gr.child.sys_id + '') !== (fHypervisorGr.sys_id + '')) {
gr.child
= fHypervisorGr.sys_id;
gr.update();
}
// The other possibliy is that the sys_id matches, in which case there would be
nothing to do
done
= true;
}
}
})();
Thanks,
Santosh