-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier.js
39 lines (29 loc) · 868 Bytes
/
notifier.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
const bent = require('bent');
const os = require('os');
class Notifier {
moduleConfig = null
constructor(moduleConfig) {
this.moduleConfig = moduleConfig;
}
notify(message) {
const moduleConfig = this.moduleConfig;
const notifyUrl = moduleConfig.webhookUrl;
const poster = bent(notifyUrl, 'POST', {
'Content-Type': 'application/x-www-form-urlencoded'
});
const params = {
topic: moduleConfig.ntfyTopic??`pm2-${message.name}`,
message: `${message.description}\n${message.timestamp ? new Date(message.timestamp).toLocaleString() : ''}`,
title: `${message.name}: ${message.event}`,
priority: 3,
tags: [message.event],
};
poster('', JSON.stringify(params))
}
notifyAll(messageList) {
messageList.map((item) => {
this.notify(item);
});
}
}
module.exports = Notifier;