«

»

Monitor Era Operation Progress – ServiceNow & Era Integration

Almost same heading a for another blog post Monitor Era Operation Progress – Calm & Era Integration 🙂 the objective for this blog post is exactly the same meaning monitor Era operations from an overlying Era consumer.

The Era consumer in this case is ServiceNow and not Calm.

In this blog post i will share a ServiceNow workflow script you can use to monitor Era operations. This can be any operation you trigger via the Era API including e.g.:

  • Provisioning
  • Delete
  • Refresh
  • Clone
  • Snapshot
  • Log CatchUp

In this example i have put this monitoring script in a ServiceNow workflow consumed by a Service Catalog Item via the Process Engine Workflow specification. This specific workflow creates a MSSQL Single Instance DB but as stated we are here to check out the monitoring section so we know if the request was completed successfully or not.

I have some information required to complete the Era via ServiceNow provisioning request stored in ServiceNow tables. There is no need to do it this way but that’s what we have to deal with in this blog post:)

If we open the Workflow ProgressMonitor Run Script activity, go to the script, we’ll see a few things you need to adjust to make it work in your environment. The Run Script activity can be found in ServiceNow under Core Activities -> Utilities.

Below is a list of workflow modifications required to consume the script.

  • change “var eratarget = new GlideRecord(‘x_NUMBER_nutanix_e_backendsystems’);” to the table (within parentheses) where you store your Era server targets (IP/fqdn) or if you prefer to define it in another way e.g. hard coded.
  • Add your user_sys_id at the following line eratarget.get(‘user_sys_id’);
  • change “eratarget.target_system_fqdn_ip” to the table column holding the the Era server IP/FQDN or if you prefer to define it in another way e.g. hard coded.
  • change “var auth = new GlideRecord(‘x_NUMBER_nutanix_e_authentication’);” to the table (within parentheses) where you store your user credentials or if you prefer to define it in another way e.g. hard coded via line:
    • request.setBasicAuth
  • MIDSERVER – for your mid server.

The monitoring script will continue to run as long as status is set to ongoing which is determined every 60 sec. So there is no script timeout in this case. When completed the script will set status to success or failed and continue form there.

This is how it looks when the monitoring script is running.

  1. Script is starting
  2. Ongoing monitoring
  3. Monitoring completed – this time with a successful result (which is good)

Monitoring Script

// Era Operations Monitoring Script
//
// Define target back end system based on table 
var eratarget = new GlideRecord('x_NUMBER_nutanix_e_backendsystems');
eratarget.get('user_sys_id');
var fqdn_ip = eratarget.target_system_fqdn_ip;
var uri = '/era/v0.9/operations/';
var url = fqdn_ip +uri +workflow.scratchpad.aid;
//
// Define sleep function
function sleep(milliseconds) {
			var start = new Date().getTime();
			for (var i = 0; i < 1e10; i++) { if ((new Date().getTime() - start) > milliseconds){
					break;
				}
			}
		}
// Start the monitoring loop
do {
// 
// REST API Call Definition
var request = new sn_ws.RESTMessageV2();
var auth = new GlideRecord('x_NUMBER_nutanix_e_authentication');
auth.get('3facbb571bs8632423ec631d7dc4bcb5c');
request.setRequestHeader("Accept","application/json");
request.setRequestHeader("Content-Type","application/json");
request.setBasicAuth(auth.userid, auth.password.getDecryptedValue());
request.setHttpMethod('GET');
request.setMIDServer('MIDSERVER');
// 
// Send REST Request
request.setEndpoint(url);
//
// Get REST API Call response
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parsedResponse = JSON.parse(responseBody);
var op_status_id = parsedResponse.status+ '';
var op_percent_complete = parsedResponse.percentageComplete+ '';
workflow.scratchpad.monitorstatus = parsedResponse.status+ '';
workflow.scratchpad.notificationstatus = workflow.scratchpad.monitorstatus+'';
// Check how things are progressing
if (op_status_id == "2"|| op_status_id == "3" || op_status_id == "4" || op_status_id == "9" || op_status_id == "11" ) {
 finished = true;
 status = 'failed';
	gs.info("ProgressMonitor: - Operation Status: " + workflow.scratchpad.monitorstatus);
	gs.info("ProgressMonitor: - Faiure identified");
	break;
}
else if (op_percent_complete == 100 && op_status_id == 5) {
 finished = true;
 status = 'success';
	gs.info("ProgressMonitor: - Operation Status: " + workflow.scratchpad.monitorstatus);
		gs.info("ProgressMonitor: - Success identified");
	break;
}
else {
 finished = false;
 status = 'ongoing';
	gs.info("ProgressMonitor: - Operation Status: " + workflow.scratchpad.monitorstatus);
	gs.info("ProgressMonitor: - Keep on going, not finished yet");
	sleep(60000);
}
}
while (status == 'ongoing');

————————————————————————————————————————————————————————-