Skip to content

Instantly share code, notes, and snippets.

@noorul
Created September 24, 2018 12:39
Show Gist options
  • Save noorul/cf70b256c6dea2358b8c1d967d84885d to your computer and use it in GitHub Desktop.
Save noorul/cf70b256c6dea2358b8c1d967d84885d to your computer and use it in GitHub Desktop.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// Calcuate signature for verification using request headers, data and token
var centralService = request.getHeader('X-Central-Service');
var centralDeliveryId = request.getHeader('X-Central-Delivery-ID');
var centralDeliveryTimestamp = request.getHeader('X-Central-Delivery-Timestamp');
var token = "<webhook_token>"; // Webhook token
var body = request.body.dataString;
var message = body + centralService + centralDeliveryId + centralDeliveryTimestamp;
var calculatedSign = new Hashes.SHA256().b64_hmac(token, message);
var signFromServer = request.getHeader('X-Central-Signature'); // Signature sent by Aruba Central
if (calculatedSign == signFromServer) {
event = JSON.parse(body);
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = event.alert_type;
inc.state = 1;
inc.description = event.description;
inc.insert();
response.setStatus(200);
response.setBody({status: "success"});
} else {
response.setStatus(200);
response.setBody({status: "failure"});
}
})(request, response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment