Last active
October 14, 2021 09:16
-
-
Save coulof/f5e17057d78ede39a7b66d818996fa53 to your computer and use it in GitHub Desktop.
CloudIQ to ServiceNow
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
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { | |
var requestBody = request.body; | |
var requestData = requestBody.data; // variable holds JSON data | |
var eventType = request.getHeader('x-ciq-event'); | |
// Answer 200 to CloudIQ Webhook test button | |
if (eventType === 'ping') { | |
response.setStatus(200); | |
} else if (eventType === 'health-score-change') { | |
var processedData = false; | |
// Create new incidents | |
if (requestData.newIssues.length > 0) { | |
requestData.newIssues.forEach(function(value, i) { | |
var gr = new GenclideRecord('incident'); | |
gr.initialize(); | |
gr.active = true; | |
gr.short_description = requestData.systemName + ' ' + requestData.systemModel + ' ' + value.ruleId; | |
gr.description = requestData.newIssues[i].description; | |
if (requestData.currentScore >= 95) { | |
gr.urgency = 3; | |
} else if (requestData.currentScore < 95 || requestData.currentScore > 70) { | |
gr.urgency = 2; | |
} else { | |
gr.urgency = 1; | |
} | |
gr.insert(); // Creates a new record | |
processedData = true; | |
}); | |
} | |
if (requestData.resolvedIssues.length > 0) { | |
// If an active incident exists (i.e. same descriptions and active); close it | |
requestData.resolvedIssues.forEach(function(value, i) { | |
var gr = new GlideRecord('incident'); | |
gr.addQuery('active', true); | |
gr.addQuery('short_description', requestData.systemName + ' ' + requestData.systemModel + ' ' + value.ruleId); | |
gr.addQuery('description', requestData.resolvedIssues[i].description); | |
gr.query(); | |
while (gr.next()) { | |
gr.active = false; | |
gr.update(); | |
} | |
processedData = true; | |
}); | |
} | |
if (processedData) { | |
response.setStatus(200); | |
} else { | |
response.setStatus(412); | |
} | |
} else { | |
response.setStatus(406); | |
} | |
})(request, response); |
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
#!/bin/bash | |
HEADERS_FILE=${HEADERS_FILE-./headers.json} | |
PAYLOAD_FILE=${PAYLOAD_FILE-./payload.json} | |
ENDPOINT=${ENDPOINT-https://webhook.site/6fd7d650-1b5b-4b8c-9781-2043005bdf2d} | |
mapfile -t HEADERS < <(jq -r '. | to_entries[] | "-H \(.key):\(.value)"'< ${HEADERS_FILE}) | |
curl -k -H "Content-Type: application/json" ${HEADERS[@]} --request POST --data @${PAYLOAD_FILE} ${ENDPOINT} |
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
{ | |
"type": "object", | |
"properties": { | |
"systemDisplayIdentifier": { | |
"type": "string" | |
}, | |
"systemName": { | |
"type": "string" | |
}, | |
"systemModel": { | |
"type": "string" | |
}, | |
"timestamp": { | |
"type": "number" | |
}, | |
"timestampIso8601": { | |
"type": "string" | |
}, | |
"currentScore": { | |
"type": "integer" | |
}, | |
"newIssues": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"impact": { | |
"type": "integer" | |
}, | |
"description": { | |
"type": "string" | |
}, | |
"resolution": { | |
"type": "string" | |
}, | |
"ruleId": { | |
"type": "string" | |
}, | |
"category": { | |
"type": "string", | |
"enum": [ | |
"SYSTEM_HEALTH", | |
"CONFIGURATION", | |
"CAPACITY", | |
"PERFORMANCE", | |
"DATA_PROTECTION" | |
] | |
}, | |
"impactedObjects": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"resolvedIssues": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"impact": { | |
"type": "integer" | |
}, | |
"description": { | |
"type": "string" | |
}, | |
"resolution": { | |
"type": "string" | |
}, | |
"ruleId": { | |
"type": "string" | |
}, | |
"category": { | |
"type": "string", | |
"enum": [ | |
"SYSTEM_HEALTH", | |
"CONFIGURATION", | |
"CAPACITY", | |
"PERFORMANCE", | |
"DATA_PROTECTION" | |
] | |
}, | |
"impactedObjects": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment