-
Notifications
You must be signed in to change notification settings - Fork 2
/
rocketchat_newrelic_incoming.js
62 lines (61 loc) · 1.79 KB
/
rocketchat_newrelic_incoming.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Script {
process_incoming_request({ request }) {
var webhookPayload = request.content;
var webhookType = String(Object.keys(webhookPayload)[0]);
var alertColor = "warning";
if( webhookType == "alert" )
{
var webhookAlert = JSON.parse(webhookPayload.alert);
if(webhookAlert.long_description.indexOf('Alert') !== -1 && webhookAlert.long_description.indexOf('opened') !== -1 ) { alertColor = "danger";}
// else if ( webhookAlert.severity == "warning"){ alertColor = "warning";}
else{ alertColor = "good"; webhookAlert.severity = "normal";}
return {
content:{
attachments: [{
title: webhookAlert.message,
pretext: webhookAlert.short_description,
title_link: webhookAlert.alert_url,
text: webhookAlert.long_description,
color: alertColor,
fields: [
{
title: "Status",
value: webhookAlert.severity
}
]
}]
}
};
}
else if( webhookType == "deployment")
{
var webhookDeployment = JSON.parse(webhookPayload.deployment);
alertColor = "good";
return {
content:{
attachments: [{
title: 'Deployment of ' + webhookDeployment.application_name,
title_link: webhookDeployment.deployment_url,
color: alertColor,
fields: [
{
title: "Revision",
value: webhookDeployment.revision
},
{
title: "Deployer",
value: webhookDeployment.deployed_by
}
]
}]
}
};
}
return {
error: {
success: false,
message: 'Error'
}
};
}
}