diff options
author | Minteck <contact@minteck.org> | 2022-11-28 17:14:38 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-11-28 17:14:38 +0100 |
commit | 18efd30a263ec0d79a26a82cbd8c90c9f81056b7 (patch) | |
tree | aea01bf3506dda706719fc68eb37b77ed9ef3fe8 /src/core/Notification.ts | |
download | autoreport-18efd30a263ec0d79a26a82cbd8c90c9f81056b7.tar.gz autoreport-18efd30a263ec0d79a26a82cbd8c90c9f81056b7.tar.bz2 autoreport-18efd30a263ec0d79a26a82cbd8c90c9f81056b7.zip |
Diffstat (limited to 'src/core/Notification.ts')
-rw-r--r-- | src/core/Notification.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/core/Notification.ts b/src/core/Notification.ts new file mode 100644 index 0000000..0ab838d --- /dev/null +++ b/src/core/Notification.ts @@ -0,0 +1,41 @@ +import AutoreportBase from "./AutoreportBase"; +import {Report, ReportSeverity} from "../types/Report"; + +export default class Notification extends AutoreportBase { + service: string; + report: Report; + + constructor(report: Report) { + super(); + this.service = report.service; + this.report = report; + } + + public async send() { + let message: string; + + switch (this.report.severity) { + case ReportSeverity.Low: message = "Service " + this.service + " has encountered a minor error"; break; + case ReportSeverity.Medium: message = "Service " + this.service + " has encountered an error"; break; + case ReportSeverity.High: message = "Service " + this.service + " has encountered a major error"; break; + case ReportSeverity.Critical: message = "Service " + this.service + " has encountered a critical error"; break; + case ReportSeverity.Fatal: message = "Service " + this.service + " has encountered a fatal error"; break; + } + + await fetch("https://" + AutoreportBase.config.notifications.server, { + method: "POST", + body: JSON.stringify({ + topic: AutoreportBase.config.notifications.topic, + message, + title: "A service encountered an error", + tags: [ "crash", "service:" + this.service ], + priority: 3, + actions: [{ "action": "view", "label": "Open report", "url": AutoreportBase.config.base + "/#/report/" + this.report.id }] + }), + headers: { + "Authorization": "Basic " + Buffer.from(AutoreportBase.config.notifications.user + ":" + AutoreportBase.config.notifications.password).toString("base64"), + "Content-Type": "application/json" + } + }) + } +}
\ No newline at end of file |