Cada payload de evento es un objeto JSON con propiedades de objetos event y data. El objeto event contiene el evento, y la propiedad data contiene una representación del recurso en el momento en que se emitió el evento.
Cada solicitud HTTP de webhook incluye un encabezado X-Rootly-Signature, utilizado para verificar que la solicitud provino de Rootly. El encabezado de firma contiene una marca de tiempo con el prefijo t= y una firma con el prefijo v= .
Para verificar la solicitud, concatena la marca de tiempo con el cuerpo de la solicitud y genera un resumen HMAC SHA256 utilizando el secreto del webhook disponible en la configuración del webhook. El resumen HMAC debe coincidir con la firma proporcionada.
Ruby
Copy
Ask AI
require 'openssl'# Assuming 'request' is an object representing the incoming HTTP requestheader = request.headers['X-Rootly-Signature']parts = header.split(',')timestamp = parts[0].split('t=').lastsignature = parts[1].split('v1=').lastsecret = 'webhook secret'# Reading the request bodyrequest_body = request.body# Create a signature using HMAC SHA256expected_signature = OpenSSL::HMAC.hexdigest('SHA256', secret, timestamp + request_body)# Compare the computed signature with the received signatureis_valid = expected_signature == signature
Python
Copy
Ask AI
import hmacimport hashlibheader = request.headers['X-Rootly-Signature']parts = header.split(',')timestamp = parts[0].split('t=')[1]signature = parts[1].split('v1=')[1]secret = "webhook secret"# Reading the request bodyrequest_body = request.data # or request.body depending on the framework# Create a signature using HMAC SHA256expected_signature = hmac.new( key=secret.encode(), msg=(timestamp + request_body).encode(), digestmod=hashlib.sha256).hexdigest()# Compare the computed signature with the received signatureis_valid = expected_signature == signature
JS
Copy
Ask AI
const crypto = require('crypto');// Assuming 'request' is an object representing the incoming requestconst header = request.headers['x-rootly-signature'];const parts = header.split(',');const timestamp = parts[0].split('t=')[1];const signature = parts[1].split('v1=')[1];const secret = "webhook secret";// Reading the request body// Ensure that the request body is raw or a stringconst request_body = request.body; // Create a HMAC SHA256 signatureconst expectedSignature = crypto.createHmac('sha256', secret) .update(timestamp + request_body) .digest('hex');// Compare the computed signature with the received signatureconst isValid = expectedSignature === signature;