-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase-alert.js
More file actions
145 lines (131 loc) · 4.73 KB
/
base-alert.js
File metadata and controls
145 lines (131 loc) · 4.73 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const { ButtonBuilder, ActionRowBuilder, ButtonStyle, EmbedBuilder } = require('discord.js');
const discord_key = process.env.DISCORD_TOKEN
const slackBotToken = process.env.SLACK_TOKEN
const slack = require('../components/slack')
const discord = require('../components/discord')
const alertTypes = {
DOS_DETECTION: 'dosDetectionIncident',
MALWARE_CATCH: 'malwareCatch',
WAF_INCIDENT: 'wafIncident'
};
class BaseAlert {
alertName;
alertType;
alertData;
constructor(alertData) {
this.alertData = alertData
}
async sendAlertToSlack() {
if (!slackBotToken) {
return;
}
let blockMessage = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "DoS Alert",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": `*ServerID*\n ${this.alertData.serverId}`
},
{
"type": "mrkdwn",
"text": `*Threshold*\n ${this.alertData.threshold}`
},
{
"type": "mrkdwn",
"text": `*ServerName*\n ${this.alertData.serverName}`
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":bitninja: View on BitNinja",
"emoji": true
},
"value": "click_me_123",
"url": `https://console.bitninja.io/server/${this.alertData.serverId}`
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":whm: View WHM",
"emoji": true
},
"value": "click_me_123",
"url": `https://${this.alertData.serverName}:2087`
}
]
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": `AlertId: ${this.alertData.alertId}`,
"emoji": true
}
]
}
];
await slack.chat.postMessage({
channel: `#${process.env.SLACK_CH}`,
text: `Malware Alert on ${this.alertData.serverName}`,
blocks: blockMessage
});
const date = new Date();
const isoDate = date.toISOString();
console.log(`[` + isoDate + `] Slack Notification | ${this.alertData.alertId}`);
}
async sendAlertToDiscord() {
if (discord_key) {
return;
}
const notificationEmbed = new EmbedBuilder()
.setTitle(this.alertName)
.setDescription('The threshold has been reached in the last 30 minutes.')
.setColor('#E84545')
.addFields(
{ name: 'ServerID', value: this.alertData.serverId.toString(), inline: true },
{ name: 'ServerName', value: this.alertData.serverName.toString(), inline: true },
{ name: 'Threshold', value: this.alertData.threshold.toString(), inline: true },
)
//.setAuthor('BitNinja Alert')*/
.setFooter({ text: `alertId: ${this.alertData.alertId}` })
.setTimestamp();
const button1 = new ButtonBuilder()
.setLabel('WHM Access')
.setStyle(ButtonStyle.Link)
.setURL(`https://${this.alertData.serverName}:2087`);
const button2 = new ButtonBuilder()
.setLabel('View on BitNinja')
.setStyle(ButtonStyle.Link)
.setURL(`https://console.bitninja.io/server/${this.alertData.serverId}`);
const row = new ActionRowBuilder().addComponents(button1, button2)
const channel = await discord.channels.fetch(process.env.DISCORD_CH); // replace CHANNEL_ID with the ID of the channel you want to send the message to
await channel.send({ embeds: [notificationEmbed], components: [row] });
}
}
module.exports = {
BaseAlert,
alertTypes
}