Created
April 22, 2015 20:50
-
-
Save ryanhoskin/f6381ed2048d37c9374a to your computer and use it in GitHub Desktop.
Filter out ServiceNow incidents that don't have a PagerDuty Service API Key associated with the assigned group.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// High priority incident escalated - use PagerDuty to find Assigned to | |
// To support auto-escalated incidents, needed to add Advanced Script Condition | |
// Evaluates Filter conditions and then advanced conditions (not either/or) | |
// 1. changes() is not respected on a record insert | |
// 2. evaluates filter conditions (on When to run pane) before script conditions | |
// 3. auto-escalated events trap on current.operation() == insert | |
// 4. also needed to change into an 'after' event | |
// Create an incident in PagerDuty for this service (lookup based on Escalation Group) | |
var debug = true; | |
if (debug) gs.log("Entered for " + current.number, "BR:Trigger PagerDuty Incident"); | |
if (true ) { | |
var pd = new PagerDuty_REST(); | |
// Lookup service key | |
var key = current.assignment_group.u_pagerduty_service.toString(); | |
if (key != "") { | |
if (debug) gs.log("key=" + key, "BR:Trigger PagerDuty Incident"); | |
// Construct JSON object | |
var body = current.number + ":" + current.short_description; | |
var details = {AssignmentGroup: current.assignment_group.name.toString(), | |
Priority: current.priority.getDisplayValue(), | |
WorkNote: current.work_notes.toString()}; | |
if (debug) JSUtil.logObject(details, "BR:Trigger PagerDuty Incident"); | |
// Create PD incident | |
var pd_incident = pd.triggerIncident(key, current.sys_id.toString(), current.number, body, details); | |
if (!pd.hasError) { | |
gs.addInfoMessage("PagerDuty incident created: " + pd_incident); | |
current.u_pagerduty = pd_incident; | |
current.update(); | |
} else { | |
gs.addErrorMessage("PagerDuty integration error: " + pd.errMsg + ". Re-escalate or contact the ServiceNow system administrators."); | |
gs.logError("PagerDuty integration failed: incident=" + current.number + ", key=" + key, "BR:Trigger PagerDuty Incident"); | |
current.work_notes = "PagerDuty integration error: " + pd.errMsg + ". Re-escalate or contact the ServiceNow system administrators."; | |
current.update(); | |
} | |
} | |
} | |
if (debug) gs.log("Exiting", "BR:Trigger PagerDuty Incident"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment