elliot
1
I created this script when setting up an inbound webhook to get notifications from any status page built with Atlassian Statuspage:
const CHANNEL = "#incidents"
class Script {
process_incoming_request({ request }) {
console.log("Atlassian Statuspage Webhook Request", request.content)
const incident = request.content.incident
const latestUpdate = incident.incident_updates[0]
return {
content: {
text: incident.name,
channel: CHANNEL,
attachments: [
{
color: getAttachmentColor(incident.status),
title: s.humanize(incident.status),
title_link: incident.shortlink,
text: latestUpdate.body,
},
],
},
}
}
}
function getAttachmentColor(status) {
switch (status) {
case "identified":
case "investigating":
case "in_progress":
return "#f4452a"
case "verifying":
case "monitoring":
case "scheduled":
return "#f4a02a"
case "completed":
case "resolved":
return "#05b870"
default:
return "#c9d0d9"
}
}
1 Like
elliot
4
V2 with support for component updates as well as incident updates:
const CHANNEL = "#incidents"
class Script {
process_incoming_request({ request }) {
console.log("Atlassian Statuspage Webhook Request", request.content)
const type = request.content.incident
? "incident"
: request.content.component
? "component"
: "unknown"
switch (type) {
case "incident": {
const incident = request.content.incident
const latestUpdate = incident.incident_updates[0]
return {
content: {
text: incident.name,
channel: CHANNEL,
attachments: [
{
color: getAttachmentColor(incident.status),
title: humanizeString(incident.status),
title_link: incident.shortlink,
text: latestUpdate.body,
},
],
},
}
}
case "component": {
const page = request.content.page
const component = request.content.component
return {
content: {
text: component.name,
channel: CHANNEL,
attachments: [
{
color: getAttachmentColor(component.status),
fields: [
{
title: "Status",
value: humanizeString(component.status),
short: true,
},
{
title: "Details",
value: page.status_description,
short: false,
},
],
},
],
},
}
}
}
}
}
function getAttachmentColor(status) {
switch (status) {
case "identified":
case "investigating":
case "in_progress":
case "partial_outage":
case "major_outage":
return "#f4452a"
case "verifying":
case "monitoring":
case "scheduled":
case "under_maintenance":
case "degraded_performance":
return "#f4a02a"
case "operational":
case "completed":
case "resolved":
return "#05b870"
default:
return "#c9d0d9"
}
}
function humanizeString(string) {
string = string
.toLowerCase()
.replace(/[_-]+/g, " ")
.replace(/\s{2,}/g, " ")
.trim()
string = string.charAt(0).toUpperCase() + string.slice(1)
return string
}