|
|
@@ -31,7 +31,7 @@ export class HttpCheckController {
|
|
|
|
|
|
this.scheduleCheck(conf);
|
|
|
|
|
|
- Logger.info('[INFO] Initial HTTP Service Check for', conf.title, '...');
|
|
|
+ Logger.info('Initial HTTP Service Check for', conf.title, '...');
|
|
|
await this.runCheck(conf);
|
|
|
}
|
|
|
} catch (err) {
|
|
|
@@ -69,7 +69,7 @@ export class HttpCheckController {
|
|
|
let interval = Number(conf.interval);
|
|
|
if (Number.isNaN(interval)) interval = defaults.serviceChecks.interval;
|
|
|
|
|
|
- if (log) Logger.info(`[INFO] Starting HTTP Service Check Controller for "${conf.title}" with interval ${interval} seconds ...`);
|
|
|
+ if (log) Logger.info(`Starting HTTP Service Check Controller for "${conf.title}" with interval ${interval} seconds ...`);
|
|
|
const id = Timer.instance.subscribe(interval, async () => await this.runCheck(conf));
|
|
|
const sub = { id, interval, conf };
|
|
|
this.subscriptions.push(sub);
|
|
|
@@ -77,7 +77,7 @@ export class HttpCheckController {
|
|
|
}
|
|
|
|
|
|
private rescheduleCheck(conf: HttpCheckConfig, sub?: Subscriber) {
|
|
|
- Logger.info('[INFO] Rescheduling HTTP Service Check for', conf.title);
|
|
|
+ Logger.info('Rescheduling HTTP Service Check for', conf.title);
|
|
|
this.unscheduleCheck(sub, false);
|
|
|
this.scheduleCheck(conf, false);
|
|
|
}
|
|
|
@@ -85,13 +85,13 @@ export class HttpCheckController {
|
|
|
private unscheduleCheck(sub?: Subscriber, log = true) {
|
|
|
if (!sub) return;
|
|
|
|
|
|
- if (log) Logger.info('[INFO] Removing HTTP Service Check for', sub.conf.title);
|
|
|
+ if (log) Logger.info('Removing HTTP Service Check for', sub.conf.title);
|
|
|
Timer.instance.unsubscribe(sub.id);
|
|
|
this.subscriptions = this.subscriptions.filter(s => s.id !== sub.id);
|
|
|
}
|
|
|
|
|
|
public async runCheck(conf: HttpCheckConfig, db?: HealthCheckDataProvider) {
|
|
|
- Logger.debug('[DEBUG] TICK', new Date(), JSON.stringify(conf));
|
|
|
+ Logger.debug('TICK', new Date(), JSON.stringify(conf));
|
|
|
|
|
|
const now = new Date();
|
|
|
const options: AxiosRequestConfig<any> = {
|
|
|
@@ -110,7 +110,7 @@ export class HttpCheckController {
|
|
|
conf = (await db.getHttpCheckConfigByID(conf.serverId ?? 0, id)) as HttpCheckConfig;
|
|
|
|
|
|
if (!conf) {
|
|
|
- Logger.warn(`[WARN] HealthCheckConfig(${id}) not found in Database but still scheduled in Timer!`);
|
|
|
+ Logger.warn(`HealthCheckConfig(${id}) not found in Database but still scheduled in Timer!`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -129,18 +129,18 @@ export class HttpCheckController {
|
|
|
try {
|
|
|
const lastErrors = await db.getLastErrors(conf.id, conf.notifyThreshold + 1);
|
|
|
if (lastErrors.length > conf.notifyThreshold) {
|
|
|
- Logger.debug(`[DEBUG] Sending [RECOVERY] FCM Notification for`, conf.title);
|
|
|
+ Logger.debug(`Sending [RECOVERY] FCM Notification for`, conf.title);
|
|
|
await FCMController.instance.sendNotificationToTopic(defaults.fcmTopics.services, {
|
|
|
title: `[RECOVERY] ${moment(now).format('HH:mm')} ${conf.title}: [OK]`,
|
|
|
body: `HTTP Check '${conf.title}' has recovered to [OK].`
|
|
|
});
|
|
|
}
|
|
|
} catch (err) {
|
|
|
- Logger.error('[ERROR] Notification failure:', err);
|
|
|
+ Logger.error('Notification failure:', err);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Logger.debug(`[DEBUG] HTTP Service Check "${conf.title}": OK.`);
|
|
|
+ Logger.debug(`HTTP Service Check "${conf.title}": OK.`);
|
|
|
await db.insertHealthCheckData(conf.id, now, HttpCheckStatus.OK, 'OK');
|
|
|
}
|
|
|
} catch (err) {
|
|
|
@@ -157,18 +157,18 @@ export class HttpCheckController {
|
|
|
await db.insertHealthCheckData(conf.id, now, HttpCheckStatus.RequestFailed, err.message);
|
|
|
}
|
|
|
} catch (insertErr) {
|
|
|
- Logger.error(`[ERROR] Inserting HealthCheckData on Error failed:`, insertErr);
|
|
|
+ Logger.error(`Inserting HealthCheckData on Error failed:`, insertErr);
|
|
|
log = true;
|
|
|
}
|
|
|
} else {
|
|
|
try {
|
|
|
await db.insertHealthCheckData(conf.id, now, HttpCheckStatus.Unknown, new String(err).toString());
|
|
|
} catch (insertErr) {
|
|
|
- Logger.error(`[ERROR] Inserting HealthCheckData on Error failed:`, insertErr);
|
|
|
+ Logger.error(`Inserting HealthCheckData on Error failed:`, insertErr);
|
|
|
}
|
|
|
log = true;
|
|
|
}
|
|
|
- if (log) Logger.error('[ERROR] HTTP Service Check failed:', err);
|
|
|
+ if (log) Logger.error('HTTP Service Check failed:', err);
|
|
|
} finally {
|
|
|
try {
|
|
|
await db.close();
|
|
|
@@ -179,7 +179,7 @@ export class HttpCheckController {
|
|
|
try {
|
|
|
const lastErrors = await db.getLastErrors(conf.id, conf.notifyThreshold + 1);
|
|
|
if (lastErrors.length > conf.notifyThreshold) {
|
|
|
- Logger.debug(`[DEBUG] Sending [CRIT] FCM Notification for`, conf.title);
|
|
|
+ Logger.debug(`Sending [CRIT] FCM Notification for`, conf.title);
|
|
|
const lastCheck = lastErrors[0];
|
|
|
const lastError = lastCheck.data[0];
|
|
|
await FCMController.instance.sendNotificationToTopic(defaults.fcmTopics.services, {
|
|
|
@@ -190,14 +190,14 @@ export class HttpCheckController {
|
|
|
});
|
|
|
}
|
|
|
} catch (err) {
|
|
|
- Logger.error('[ERROR] Notification failure:', err);
|
|
|
+ Logger.error('Notification failure:', err);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private recurseDisjunctChecks(checks: CheckDisjunction, responseText: string): ContentCheckError[] {
|
|
|
const errorBuffer: ContentCheckError[] = [];
|
|
|
- Logger.debug(`[DEBUG] Processing ${checks.length} disjunctive checks ...`);
|
|
|
+ Logger.debug(`Processing ${checks.length} disjunctive checks ...`);
|
|
|
for (const check of checks) {
|
|
|
const errors: ContentCheckError[] = [];
|
|
|
if (typeof check === 'string') {
|
|
|
@@ -220,13 +220,13 @@ export class HttpCheckController {
|
|
|
return [];
|
|
|
}
|
|
|
}
|
|
|
- Logger.debug(`[DEBUG] All disjunctive checks failed, collected ${errorBuffer.length} errors`);
|
|
|
+ Logger.debug(`All disjunctive checks failed, collected ${errorBuffer.length} errors`);
|
|
|
return errorBuffer;
|
|
|
}
|
|
|
|
|
|
private recurseConjunctChecks(check: CheckConjunction, responseText: string): ContentCheckError[] {
|
|
|
const errorBuffer: ContentCheckError[] = [];
|
|
|
- Logger.debug(`[DEBUG] Processing ${check.and.length} conjunctive checks ...`);
|
|
|
+ Logger.debug(`Processing ${check.and.length} conjunctive checks ...`);
|
|
|
for (const con of check.and) {
|
|
|
try {
|
|
|
if (typeof con === 'string') {
|
|
|
@@ -242,16 +242,16 @@ export class HttpCheckController {
|
|
|
} else throw error;
|
|
|
}
|
|
|
}
|
|
|
- Logger.debug(`[DEBUG] Ran through conjunctive checks, collected ${errorBuffer.length} errors`);
|
|
|
+ Logger.debug(`Ran through conjunctive checks, collected ${errorBuffer.length} errors`);
|
|
|
return errorBuffer;
|
|
|
}
|
|
|
|
|
|
private doCheck(check: string, responseText: string) {
|
|
|
const reg = new RegExp(check, 'i');
|
|
|
if (!reg.test(responseText)) {
|
|
|
- Logger.debug(`[DEBUG] Regular expression /${check}/i not found in response`);
|
|
|
+ Logger.debug(`Regular expression /${check}/i not found in response`);
|
|
|
throw { type: 'contentCheck', status: HttpCheckStatus.CheckFailed, message: `Regular expression /${check}/i not found in response` };
|
|
|
}
|
|
|
- Logger.debug(`[DEBUG] RegExp check /${check}/i successful ✔︎`);
|
|
|
+ Logger.debug(`RegExp check /${check}/i successful ✔︎`);
|
|
|
}
|
|
|
}
|