class Script {
process_incoming_request({ request }) {
var webhookPayload = request.content;
var webhookIncidentId = webhookPayload.incident_id;
var webhookSeverity = webhookPayload.severity;
var webhookCurrentState = webhookPayload.current_state;
var webhookPolicyName = webhookPayload.policy_name;
var webhookConditionName = webhookPayload.condition_name;
var alertColor = "warning";
var channels = ["#cloud-team"];
if(webhookCurrentState === "open") { alertColor = "danger";}
if(webhookPolicyName === "Project A") { channels.push("#ProjectA"); }
else if(webhookPolicyName === "Project B") { channels.push("#ProjectB"); }
//console.log(request.content);
//console.log("Channels: " + channels.join(", "));
return {
content:{
channel: channels,
attachments: [{
title: webhookSeverity + ' - ' + webhookPolicyName,
text: "Condition: " + webhookConditionName + "\nIncident Id: " + webhookIncidentId,
color: alertColor,
fields: [
{
title: "Status",
value: webhookCurrentState
}
]
}]
}
};
};
};