Skip to content

Instantly share code, notes, and snippets.

@aKamrani
Last active February 13, 2025 10:47
Show Gist options
  • Select an option

  • Save aKamrani/b478ef00d240d55d6c71f2b39fe0fc04 to your computer and use it in GitHub Desktop.

Select an option

Save aKamrani/b478ef00d240d55d6c71f2b39fe0fc04 to your computer and use it in GitHub Desktop.
Grafana alert RocketChat webhook script
// Rocketchat incoming grafana webhook script
// This script is for Rocketchat when defining an integration in Administartion / Workspace / Integration panel
// See the following links for some documentation:
// * Grafana outgoing format: https://grafana.com/docs/grafana-cloud/alerting-and-irm/irm/incident/configure/integrations/configure-outgoing-webhooks/
// * Rocketchat incoming message format: https://developer.rocket.chat/reference/api/rest-api/endpoints/core-endpoints/chat-endpoints/postmessage#attachments-detail
class Script {
process_incoming_request({ request }) {
var alerts = request.content.alerts[0];
var panelURL = alerts.panelURL;
var dashboardURL = alerts.dashboardURL;
var editURL = alerts.generatorURL;
var silenceURL = alerts.silenceURL;
let color = "#00FF00"; // green
switch(request.content.status) {
case 'resolved':
color = '#00FF00';
emoji = '✅ RESOLVED ✅';
break;
case 'firing':
color = '#FF0000';
emoji = '🚨 ALERT 🚨';
break;
default:
color = '#666666';
}
return {
content:{
text: `${emoji}`+ "\n\n" + request.content.commonLabels.alertname + "\n" + request.content.commonAnnotations.summary + "\n" + request.content.commonAnnotations.description+ "\n\n" + request.content.value,
"attachments": [{
"color": color,
"fields": [
{
"short": true,
"title": "View Metric Panel",
"value": "[Panel](" + `${panelURL}` + ")"
},
{
"short": true,
"title": "View Dashboard",
"value": "[Dashboard](" + `${dashboardURL}` + ")"
},
{
"short": true,
"title": "Edit Alert",
"value": "[Edit](" + `${editURL}` + ")"
},
{
"short": true,
"title": "Silence Alert",
"value": "[Silence](" + `${silenceURL}` + ")"
}
],
}]
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment