-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Discord webhook notification support #1612
Changes from 1 commit
28f5d35
172597e
d3810db
d83773a
84fe58b
92d9573
cc48f1d
8667f74
0bb7eae
d3fb41a
8f94062
1d9f94c
e44cbf3
aa977ce
964a923
e9bcf66
64c5aa9
01e73fe
d8379f7
f46b076
ccd6c58
ef41712
fa50706
67da574
023d943
012483d
8007daa
70ffe1b
12d9f15
07882e0
8409571
55c1a1c
ff2b3b4
6152679
e4e3f9c
f22b67a
d710ec0
c4168a5
afc9d46
03a938d
5be17af
4ef2b29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const SERVICE_NAME = "NotificationService"; | ||
import axios from 'axios'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No imports in the services please, it makes testing much more difficult 👍 There shouldn't be any imports anywhere except in the root server definition really. The exception being success/error messages There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
class NotificationService { | ||
static SERVICE_NAME = SERVICE_NAME; | ||
|
@@ -16,6 +17,26 @@ class NotificationService { | |
this.logger = logger; | ||
} | ||
|
||
async sendDiscordNotification(networkResponse, webhookUrl) { | ||
const { monitor, status } = networkResponse; | ||
const message = { | ||
content: `Monitor ${monitor.name} is ${status ? "up" : "down"}. URL: ${monitor.url}` | ||
}; | ||
|
||
try { | ||
await axios.post(webhookUrl, message); | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Network operations should be carried out from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complete. |
||
} catch (error) { | ||
this.logger.error({ | ||
message: error.message, | ||
service: this.SERVICE_NAME, | ||
method: "sendDiscordNotification", | ||
stack: error.stack, | ||
}); | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this error meant to be swallowed and operations meant to continue in event of error? If not it should have method specifics added to it and rethrown to be caught by middleware There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! |
||
} | ||
} | ||
|
||
/** | ||
* Sends an email notification for hardware infrastructure alerts | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo dawg, we need a field for that webhook URL! 🍝
While adding "discord" to the enum is a good start, we're missing a dedicated field to store the Discord webhook URL. The existing
address
field could be misused for this, but that's not clean architecture.Add a new field to properly store webhook URLs: