Description: Canary supports outgoing Webhooks from your Console to an endpoint of your choice. This event-driven approach ensures that alerts are sent to you as they happen!
In this guide, we’ll send data to your ServiceNow instance, using a Scripted Rest API endpoint.
Jump to the API Endpoint script by clicking here.
Step 1: Created a Scripted Rest API Endpoint
To get started, head over to the [Scripted Rest APIs] UI in your ServiceNow Instance.
Select the "New" button.
Specify a name for your new endpoint.
Once created, note down your custom endpoint URL. This will be a combination of your main URL and the Base API path. In our example the endpoint URL is:
https://dev258141.service-now.com/api/1616992/thinkst_canary
When you're ready select your new endpoint.
Step 2: Add a resource to your endpoint
With your new endpoint in view, click "New" under the Resources tab.
Enter a name for your resource, select the POST method, and paste the below script into the editor. Once complete make sure to uncheck the "Requires Authentication" checkbox, as we'll handle authentication within the script instead.
Line 3 of the script requires a secret string which we'll use to authenticate to this endpoint later. Be sure to set it to something you'd like to use as a credential for your webhook later.
API Endpoint Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// Auth token (Replace this any string you'd prefer)
var AUTH_TOKEN = "88c95eec1a61350df4b4d104bfb06003";
// Get Authorization header
var authHeader = request.getHeader("Authorization");
// Check if auth header is missing or incorrect
if (!authHeader || authHeader !== AUTH_TOKEN) {
response.setStatus(401);
response.setBody({ message: "Unauthorized: Invalid or missing Authorization header" });
return;
}
var reqData = request.body.dataString; // Get raw JSON body
var jsonData = JSON.parse(reqData); // Parse JSON
var prettyJson = JSON.stringify(jsonData, null, 4); // Pretty print JSON
var gr = new GlideRecord('incident');
gr.newRecord();
// Extract Short Description from JSON (Case-Sensitive)
var shortDesc = jsonData["Description"] || "A New Canary Incident has been created";
// Prefix "Thinkst Canary: " to the short description
shortDesc = "Thinkst Canary: " + shortDesc;
// Set Short Description
gr.short_description = shortDesc;
gr.description = prettyJson; // Store the formatted JSON body in the description field
gr.category = "API Created";
gr.state = 1; // New
// Set Impact, Urgency, and Priority to 1 - High
gr.impact = 1;
gr.urgency = 1;
gr.priority = 1;
/*
// Set Caller to "Canary Console" (Ensure this user exists in ServiceNow)
var caller = new GlideRecord('sys_user');
caller.addQuery('name', 'Canary Console');
caller.query();
if (caller.next()) {
gr.caller_id = caller.sys_id;
}
*/
/*
// Set Service to "Thinkst Canary" (Ensure this service exists in ServiceNow)
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('name', 'Thinkst Canary');
service.query();
if (service.next()) {
gr.business_service = service.sys_id;
}
*/
var result = gr.insert(); // Insert the new record
// Response to indicate success
response.setStatus(201);
response.setBody({
message: "Incident created successfully",
sys_id: result,
short_description_set: shortDesc
});
})(request, response);
Step 3: Configure the webhook on your Console:
With the ServiceNow side of things setup, head over to your Canary Console's Global Settings.
Expand the "Webhooks" section and hit the + icon, to create a new generic webhook.
Enter the URL previously noted from ServiceNow, as well as the required headers. Don't forget to set the same secret in the Authorization header as you have configured in the script.
When you're ready, hit the "Save" button, and selecting your new webhook again allows you to send a test message.
You'll now find alerts created under the your Service Desk Incidents.