Is there a way to populate the Off/On state from the VMware Virtual Machine Instance in the Windows Server CI?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2018 01:59 PM
Hello All,
I would like a way to update the CI of the windows server whether the VM instance for this server shows Off/On/Paused. This will help me to easily know why certain CI's are not being updated through daily discovery.
We currently use the VMware integration which gathers data about each Instance through Discovery this integration shows the state of the Instance that I need. We also discover the actual server as well which provides all of the information needed such as: the OS, OS Version, Running applications, etc. I would like a way to populate important fields from both of these such as the State of the VMWare instance in the CI of the windows server.
What would be the best way to update the fields from both tables?
Thanks,
Jeremy
- Labels:
-
Discovery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 01:10 AM
Hi Mayank,
Yes, can you please the details on this, will be helpful for us.
TIA.
Ravinder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 04:50 AM
Hello.
So we are using this BR on the "Vmware Virtual machine instance" cmdb_ci_vmware_instance Table.
It works when the state of the VMI changes.
This is the Script it runs:(Advanced)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(function executeRule(current, previous /*null when async*/) {
var objServerStateUtil = new vmInstanceServerStateUtil(current);
if(current.state.changesTo('off')) {
objServerStateUtil.setServerRecord('powered_off');
}else if(current.state.changesTo('on')) {
objServerStateUtil.setServerRecord('installed');
}
})(current, previous);
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
And Here is the script include 'vmInstanceServerStateUtil' which this BR calls. So It works on the following Logic.
Whenever the state of a VMI changes:
>The BR checks the Existing instantiated:Instantiated BY Relationship in the CMDB_REL_CI table.
> If a Relationship exists it updated the "Hardware Status" of the Server Record to the following values.
1.) Powered OFF (custom value)
2.) installed (default)
> If the relationship does not exists in the CMDB_REL_CI table, the BR creates a task and assigns to our TEam QUEUE
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
var vmInstanceServerStateUtil = Class.create();
vmInstanceServerStateUtil.prototype = {
initialize: function() {
this.currentGr = current;
this.vmStatus = '';
},
setServerRecord: function(getStatus) {
if (getStatus == 'powered_off') {
this.vmStatus = 'Powered Off';
} else {
this.vmStatus = 'Powered On';
}
var _flag = 0;
var sid = this.currentGr.getValue('sys_id');
var grl = new GlideRecord('cmdb_rel_ci');
grl.addEncodedQuery('child.sys_id=' + sid + '^ORparent.sys_id=' + sid + '^type=1bb40e370a0a0b323d85a1ce84f8feae');
grl.query();
while (grl.next()) {
_flag++;
this.setCIStatus(grl.parent, grl.child, getStatus);
}
if (_flag == 0) {
var checkExistingTask = this.checkIfTaskExistsforVMCi(sid);
if (!checkExistingTask) {
this.generateDataQualityTask(this.currentGr.name.toString());
} else {
this.updateExistingTask(checkExistingTask);
}
}
if (_flag > 0) {
var checkExistingTaskOk = this.checkIfTaskExistsforVMCi(sid);
if (checkExistingTaskOk != false) {
this.closeTask(checkExistingTaskOk);
}
}
},
closeTask: function(sysID) {
var ctaskGr = new GlideRecord('sc_task');
ctaskGr.get(sysID);
ctaskGr.work_notes = 'Task is Closed as Relationship is established';
ctaskGr.state = 3;
ctaskGr.update();
},
updateExistingTask: function(sysIDtask) {
var stringErrmsg = "The VM Instance:'" + this.currentGr.name + "' State has been changed to '" + this.vmStatus + "'\n" + " 'Instantiated by' Dependencies is Missing ";
var ctaskGr = new GlideRecord('sc_task');
ctaskGr.get(sysIDtask);
ctaskGr.work_notes = stringErrmsg;
ctaskGr.variables.v_additional_comments = stringErrmsg;
ctaskGr.update();
},
checkIfTaskExistsforVMCi: function(cmCiSysID) {
var detailsString = '';
var ctaskGr = new GlideRecord('sc_task');
ctaskGr.addEncodedQuery('request_item.cat_item=e6335e4937f10308fead53b543990e7e^active=true^cmdb_ci=' + cmCiSysID);
ctaskGr.query();
if (ctaskGr.next()) {
return ctaskGr.sys_id;
} else {
return false;
}
},
setCIStatus: function(parentSysId, childSysId, getStats) {
var coSysid = this._checkCorrectSysId(parentSysId, childSysId);
var glCI = new GlideRecord('cmdb_ci_server');
if (glCI.get(coSysid)) {
glCI.setValue("hardware_status", getStats);
glCI.update();
}
},
_checkCorrectSysId: function(pSid, cSysid) {
var arr = [pSid, cSysid];
var gr = new GlideRecord("cmdb_ci");
for (var i = 0; i < arr.length; i++) {
if (gr.get(arr[i])) {
if (gr.sys_class_name != 'cmdb_ci_vmware_instance') {
return gr.sys_id;
}
}
}
},
generateDataQualityTask: function(serverName) {
var stringAppend = "The VM Instance:'" + serverName + "' State has been changed to '" + this.vmStatus + "'\n" + " 'Instantiated by' Dependencies is Missing ";
var cart = new sn_sc.CartJS();
var request = {
"sysparm_id": "e6335e4937f10308fead53b543990e7e",
"sysparm_quantity": "1",
"variables": {
"v_additional_comments": stringAppend,
"vs_department": "d3df09a8db0733801b069837db9619ce", // sysId Of platform and Asset Mgmt.
"requested_for": "6816f79cc0a8016401c5a33be04be441", // sysAdmin
}
};
var cartDetails = cart.orderNow(request);
var grCT = new GlideRecord('sc_task');
grCT.addQuery('request', cartDetails.sys_id);
grCT.query();
if (grCT.next()) {
grCT.cmdb_ci = this.currentGr.sys_id;
grCT.short_description = 'Create a request to report CMDB Data Quality Issue - Automated';
grCT.work_notes = stringAppend;
grCT.update();
}
},
type: 'vmInstanceServerStateUtil'
};
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 03:17 AM
Hi Mayank,
I am new for the development and please help for the below requirement.
Create servers in cmdb_ci_server for VM Appliances that are "on"
Two situations:
If a VM appliance is created and is marked as "on"
If a VM appliance is turned "on" and it doesn't already have a CI
Check the cmdb_ci_server record for a sys_id (of the VM appliance)
when you make a relationship down to a cmdb_ci_server, place the vm appliance's sys_id into the integration id field
a business rule on the creation of VMware virtual machine instance CIs which contain "vma" in the name and State is On. it will create a Server class CI related to it with type "Instantiates::Instantiated by".
Will also need to ensure if a VM instance Cis in the state of Off is changed to On, and create a server Ci if one does not already exist.
Set the model to "VMware, Inc. Virtualized Computer" and set the description to "Virtual Machine Appliance"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 11:35 PM
Hi Mayank,
Thanks you for the details, shall try this out !