|
@@ -115,6 +115,21 @@ export class HttpCheckController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (success) {
|
|
if (success) {
|
|
|
|
|
+ if (conf.notify) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const lastErrors = await this.db.getLastErrors(conf.id, conf.notifyThreshold + 1);
|
|
|
|
|
+ if (lastErrors.length > conf.notifyThreshold) {
|
|
|
|
|
+ Logger.debug(`[DEBUG] Sending [RECOVERY] FCM Notification for`, conf.title);
|
|
|
|
|
+ await FCMController.instance.sendNotificationToTopic(defaults.fcmTopics.services, {
|
|
|
|
|
+ title: `[RECOVERY] ${conf.title} since ${moment(now).format('HH:mm')}`,
|
|
|
|
|
+ body: `HTTP Check '${conf.title}' has recovered to [OK].`
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ Logger.error('[ERROR] Notification failure:', err);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Logger.debug(`[DEBUG] HTTP Service Check "${conf.title}": OK.`);
|
|
Logger.debug(`[DEBUG] HTTP Service Check "${conf.title}": OK.`);
|
|
|
await this.db.insertHealthCheckData(conf.id, now, HttpCheckStatus.OK, 'OK');
|
|
await this.db.insertHealthCheckData(conf.id, now, HttpCheckStatus.OK, 'OK');
|
|
|
}
|
|
}
|
|
@@ -149,13 +164,13 @@ export class HttpCheckController {
|
|
|
try {
|
|
try {
|
|
|
const lastErrors = await this.db.getLastErrors(conf.id, conf.notifyThreshold + 1);
|
|
const lastErrors = await this.db.getLastErrors(conf.id, conf.notifyThreshold + 1);
|
|
|
if (lastErrors.length > conf.notifyThreshold) {
|
|
if (lastErrors.length > conf.notifyThreshold) {
|
|
|
- Logger.debug(`[DEBUG] Sending FCM Notification for`, conf.title);
|
|
|
|
|
|
|
+ Logger.debug(`[DEBUG] Sending [CRIT] FCM Notification for`, conf.title);
|
|
|
const lastCheck = lastErrors[0];
|
|
const lastCheck = lastErrors[0];
|
|
|
const lastError = lastCheck.data[0];
|
|
const lastError = lastCheck.data[0];
|
|
|
await FCMController.instance.sendNotificationToTopic(defaults.fcmTopics.services, {
|
|
await FCMController.instance.sendNotificationToTopic(defaults.fcmTopics.services, {
|
|
|
- title: `[CRIT] ${conf.title} since ${moment(lastCheck.time).format('HH:mm')}`,
|
|
|
|
|
|
|
+ title: `[CRIT] ${conf.title} failed at ${moment(lastCheck.time).format('HH:mm')}`,
|
|
|
body:
|
|
body:
|
|
|
- `HTTP Check '${conf.title}' has failed over ${conf.notifyThreshold} times in a row\n` +
|
|
|
|
|
|
|
+ `HTTP Check '${conf.title}' has failed over ${conf.notifyThreshold} times in a row.\n` +
|
|
|
`Last error status was: (${lastError.status}) ${lastError.message}`
|
|
`Last error status was: (${lastError.status}) ${lastError.message}`
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|