Home > Storage > Data Storage Essentials > Storage Resource Manager (SRM) > Dell SRM: Automating Incident Management in ServiceNow > ServiceNow scripted REST API configuration
To trigger creation, update, closure, and reopening of ServiceNow incidents from SRM alerting, you must create a scripted REST API resource. This resource listens to HTTP POST requests from SRM, and you can respond accordingly by creating, updating, closing, and reopening an incident.
Figure 5. ServiceNow Scripted REST API – new
Figure 6. ServiceNow scripted REST API – name and API ID
The new service appears in the list under the search box.
Figure 7. ServiceNow Scripted REST API – created
The scripted REST API service configuration appears with its namespace and base API path.
Figure 8. ServiceNow scripted REST API – new resource
The scripted REST API resource configuration is displayed.
Figure 9. ServiceNow Scripted REST API – resource configuration
// SRM alert to ServiceNow incident Scripted REST API script // Incident is OPENED when SRM active=true & severity=[1-5] alert is received, and if there is no existing incident. SNOW short_description field is set to SRM alertId, which is unique alert id in SRM // Incident is CLOSED when SRM active=false alert is received for the existing short_description=alertId. No further updates to incident happen if same SRM close alert is received repeatedly // Incident is REOPENED when SRM active=true & severity=[1-5] alert is received for the existing short_description=alertId. close_code, close_notes, reopen_count, reopened_by, reopened_time are automatically updated // Incident is UPDATED when SRM active=true & severity="N/A" or null alert is received for the existing short_description=alertId. This is alert SRM update by the admin user in SRM UI. SNOW user_input prop set with values of owner and ack /* SRM alerts sent via webhook. Accepted values: null, "N/A", "", "string", "number". Not accepted: empty value or any value except null without quotes OPEN incident alert: { "alertId": "Unity-A007_Pool_Test-Pool93_Threshold Exceeded", "severity": "1", "eventType": "DURABLE", "timestamp": "1623403895", "systemName": "Unity-A007", "systemType": "UnifiedArray", "componentType": "Pool", "componentName": "Test-Pool93", "source": "Unity-GenericEvent", "category": "Capacity", "description": "Storage pool Test-Pool93 has exceeded its critical threshold of 95%", "active":"true", "acknowledged":"N/A", "owner":"N/A" } CLOSE incident alert: { "alertId": "Unity-A007_Pool_Test-Pool93_Threshold Exceeded", "severity": "1", "eventType": "DURABLE", "timestamp": "1623403895", "systemName": "Unity-A007", "systemType": "UnifiedArray", "componentType": "Pool", "componentName": "Test-Pool93", "source": "Unity-GenericEvent", "category": "Capacity", "description": "Storage pool Test-Pool93 has exceeded its critical threshold of 95%", "active":"false", "acknowledged":"N/A", "owner":"N/A" } REOPEN incident alert: { "alertId": "Unity-A007_Pool_Test-Pool93_Threshold Exceeded", "severity": "1", "eventType": "DURABLE", "timestamp": "1623403895", "systemName": "Unity-A007", "systemType": "UnifiedArray", "componentType": "Pool", "componentName": "Test-Pool93", "source": "Unity-GenericEvent", "category": "Capacity", "description": "Storage pool Test-Pool93 has exceeded its critical threshold of 95%", "active":"true", "acknowledged":"N/A", "owner":"N/A" } UPDATE incident alert: { "alertId": "Unity-A007_Pool_Test-Pool93_Threshold Exceeded", "severity":"N/A", "eventType": "DURABLE", "timestamp": "1623403895", "systemName": "Unity-A007", "systemType": "UnifiedArray", "componentType": "Pool", "componentName": "Test-Pool93", "source": "Unity-GenericEvent", "category": "Capacity", "description": "Storage pool Test-Pool93 has exceeded its critical threshold of 95%", "active":"true", "acknowledged":"yes", "owner":"Dejan" } */ (function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { var requestBody = request.body; var requestData = requestBody.data; // variable holds JSON data var eventType = request.getHeader('x-srm-event'); var processedData = false; var message = ''; var gr = new GlideRecord('incident'); switch (requestData.active) { // Close incident - if SRM active=false and incident exists (get SNOW incident where "short_description == alertId" --> assign close_code, close_notes, and set SNOW state property to 7 (closed)) // If SRM active=false alert with same alertId is sent repeatedly to SNOW after its initial closure, no further updates will happen on incident - it will remain in "closed" state, with initial "closedAt" timestamp // If SRM active=false alert is not matched with SNOW incident, nothing happens case "false": gr.addQuery('short_description', requestData.alertId); gr.query(); if (gr.getRowCount() == 1) { //there is a match, so update incident while (gr.next()) { gr.close_code = 'Solved (Permanently)'; gr.close_notes = 'SRM clear alert received, issue is resolved'; gr.state = 7; //closed state = 7 gr.comments = 'SRM alert closed'; gr.user_input = 'SRM alert closed'; gr.update(); processedData = true; //indicates that SNOW incident was updated message = "Incident closed"; } } break; // Open incident - SRM active=true & severity="1-5" and no existing incident with "short_description == alertId" case "true": gr.addQuery('short_description', requestData.alertId); gr.query(); if (gr.getRowCount() == 0 && requestData.severity != "N/A" && requestData.severity) { //there is no incident match, severity has value 1-5, so create incident gr.initialize(); gr.active = true; gr.short_description = requestData.alertId; //map SRM unique alertId to SNOW short_description property gr.description = requestData.description; //map SRM alert fullsmg (description) to SNOW description property gr.urgency = requestData.severity; //map SRM alert severity to SNOW urgency gr.impact = requestData.severity; //set impact to be the same as severity gr.subcategory = 'SRM'; //tag incident with SRM string value gr.setDisplayValue('cmdb_ci',requestData.systemName); //assign SRM device name to cmdb_ci SNOW property gr.comments = 'SRM alert created'; gr.user_input = 'SRM alert created'; gr.insert(); // Creates a new record processedData = true; //indicates that SNOW incident was created message = "Incident created"; // Update incident - SRM active=true & severity == "N/A" or null and incident exists (new or closed state), then it is existing ACTIVE SRM alert update (ack or owner assigned from SRM user in UI by right-click action) } else if (gr.getRowCount() == 1 && (requestData.severity == "N/A" || requestData.severity === null)){ while (gr.next()) { gr.active = true; //in case SRM alertId matches closed SNOW incident, make it active again (can happen if SNOW closed incident which is still active on SRM) gr.state = 1; //in case SRM alertId matches closed SNOW incident, make its state=1 again gr.comments = 'SRM user updated alert: acknowledged and/or owner assigned'; //update SNOW comments property gr.user_input = ''; if (requestData.owner){ gr.user_input = 'SRM alert owner assigned: ' + requestData.owner + ' | '; //if owner property is set by SRM user, copy it to SNOW user_input property, otherwise skip } if (requestData.acknowledged){ gr.user_input = gr.user_input + ' SRM alert acknowledged: ' + requestData.acknowledged; //if acknowledged/unacknowledged is set by SRM user, set user_input SNOW property, otherwise skip } gr.update(); processedData = true; //indicates that SNOW incident was updated message = "Incident updated"; } } // Reopen incident - SRM active=true & severity="1-5" and incident matched (new or closed state). close_code, close_notes, reopen_count, reopened_by, reopened_time are automatically updated else { while (gr.next()) { gr.active = true; gr.state = 1; gr.comments = 'SRM alert reopened'; gr.user_input = 'SRM alert reopened'; gr.update(); processedData = true; //indicates that SNOW incident was updated message = "Incident reopened"; } } break; } if (processedData) { response.setStatus(200); return message; } else { response.setStatus(412); message = 'No incident created/updated'; return message; } })(request, response);