How update CMDB in real time after changing cloud config

Nabil EL FILALI
Tera Expert

Hello 

could you please tell me how to configure Servicenow in order to update CMDB when VM stop or start running , in near  real time 

 

thank you 

1 REPLY 1

Yashsvi
Kilo Sage

Hi @Nabil EL FILALI,

To update the CMDB (Configuration Management Database) in ServiceNow in near real-time when a VM (Virtual Machine) starts or stops,
1. Set Up Event Monitoring:
- Use your cloud provider’s monitoring tools to capture VM state changes (e.g., AWS CloudWatch for AWS, Azure Monitor for Azure).

2. Configure Webhooks or Event Handlers
- Set up webhooks or event handlers to send events to ServiceNow. For example, use AWS Lambda to send HTTP requests to ServiceNow when VM state changes.

3. Create an Inbound REST API in ServiceNow
- Navigate to `System Web Services > Scripted Web Services > Scripted REST APIs`.
- Create a new Scripted REST API (e.g., `update_vm_event`).

4. Define API Resource and Script
- Add a resource to handle POST requests (e.g., `/update_state`).
- Implement a script to update the CMDB based on the VM state received.

REST API resource:

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var requestBody = request.body.data;
    var vmId = requestBody.vm_id;
    var state = requestBody.state;

    var cmdbCI = new GlideRecord('cmdb_ci_vm_instance');
    if (cmdbCI.get('instance_id', vmId)) {
        cmdbCI.state = (state == 'running') ? 'On' : 'Off';
        cmdbCI.update();
        response.setStatus(200);
        response.setBody({status: 'Success', message: 'CMDB updated successfully'});
    } else {
        response.setStatus(404);
        response.setBody({status: 'Error', message: 'VM not found in CMDB'});
    }
})(request, response);

 

 

By integrating event monitoring tools with ServiceNow via REST APIs, you can ensure that your CMDB is updated in near real-time when VMs change state. The key components involve setting up monitoring and webhooks in your cloud provider, creating a REST API endpoint in ServiceNow, and scripting the logic to update the CMDB based on the received events.

 

Thank you, please make helpful if you accept the solution.