Skip to content

Instantly share code, notes, and snippets.

@lucenarenato
Forked from ATofighi/script.js
Created April 6, 2022 02:17
Show Gist options
  • Select an option

  • Save lucenarenato/85b343b63ebc43922d1c2f70380c4d72 to your computer and use it in GitHub Desktop.

Select an option

Save lucenarenato/85b343b63ebc43922d1c2f70380c4d72 to your computer and use it in GitHub Desktop.
Grafana alert RocketChat webhook script
class Script {
/**
* @params {object} request
*/
process_incoming_request({ request }) {
let color = "#00FF00"; // green
switch(request.content.state) {
case 'ok':
color = '#00FF00';
break;
case 'paused':
color = '#666666';
break;
case 'alerting':
color = '#FF0000';
break;
case 'pending':
color = '#CCCCCC';
break;
case 'no_data':
color = '#333333';
break;
default:
color = '#666666';
}
return {
content:{
text: request.content.title,
"attachments": [{
"color": color,
"title": request.content.title,
"title_link": request.content.ruleUrl,
"text": request.content.message,
"image_url": request.content.imageUrl,
}]
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment