|
|
@@ -24,10 +24,10 @@ export class HttpCheckController {
|
|
|
const configs = await this.db.getHttpCheckConfigs();
|
|
|
|
|
|
for (const conf of configs) {
|
|
|
- if (!conf) return;
|
|
|
- if (!conf.active) return;
|
|
|
+ if (!conf) continue;
|
|
|
+ if (!conf.active) continue;
|
|
|
|
|
|
- await this.scheduleCheck(conf);
|
|
|
+ this.scheduleCheck(conf);
|
|
|
|
|
|
Logger.info('[INFO] Initial HTTP Service Check for', conf.title, '...');
|
|
|
await this.timerTick(conf);
|
|
|
@@ -40,26 +40,26 @@ export class HttpCheckController {
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
- async updateCheck(status: ServiceChangedStatus, conf: HttpCheckConfig) {
|
|
|
+ updateCheck(status: ServiceChangedStatus, conf: HttpCheckConfig) {
|
|
|
const subscriber = this.subscriptions.find(sub => sub.conf.id === conf.id);
|
|
|
|
|
|
switch (status) {
|
|
|
case ServiceChangedStatus.Created:
|
|
|
case ServiceChangedStatus.Activated:
|
|
|
- await this.scheduleCheck(conf);
|
|
|
+ this.scheduleCheck(conf);
|
|
|
break;
|
|
|
case ServiceChangedStatus.Deactivated:
|
|
|
- await this.unscheduleCheck(subscriber);
|
|
|
+ this.unscheduleCheck(subscriber);
|
|
|
break;
|
|
|
case ServiceChangedStatus.Rescheduled:
|
|
|
- await this.rescheduleCheck(conf, subscriber);
|
|
|
+ this.rescheduleCheck(conf, subscriber);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async scheduleCheck(conf: HttpCheckConfig, log = true) {
|
|
|
+ private scheduleCheck(conf: HttpCheckConfig, log = true) {
|
|
|
let interval = Number(conf.interval);
|
|
|
if (Number.isNaN(interval)) interval = defaults.serviceChecks.interval;
|
|
|
|
|
|
@@ -70,13 +70,13 @@ export class HttpCheckController {
|
|
|
return sub;
|
|
|
}
|
|
|
|
|
|
- private async rescheduleCheck(conf: HttpCheckConfig, sub?: Subscriber) {
|
|
|
+ private rescheduleCheck(conf: HttpCheckConfig, sub?: Subscriber) {
|
|
|
Logger.info('[INFO] Rescheduling HTTP Service Check for', conf.title);
|
|
|
- await this.unscheduleCheck(sub, false);
|
|
|
- await this.scheduleCheck(conf, false);
|
|
|
+ this.unscheduleCheck(sub, false);
|
|
|
+ this.scheduleCheck(conf, false);
|
|
|
}
|
|
|
|
|
|
- private async unscheduleCheck(sub?: Subscriber, log = true) {
|
|
|
+ private unscheduleCheck(sub?: Subscriber, log = true) {
|
|
|
if (!sub) return;
|
|
|
|
|
|
if (log) Logger.info('[INFO] Removing HTTP Service Check for', sub.conf.title);
|
|
|
@@ -180,6 +180,7 @@ export class HttpCheckController {
|
|
|
|
|
|
private recurseDisjunctChecks(checks: CheckDisjunction, responseText: string): ContentCheckError[] {
|
|
|
const errorBuffer: ContentCheckError[] = [];
|
|
|
+ Logger.debug(`[DEBUG] Processing ${checks.length} disjunctive checks ...`);
|
|
|
for (const check of checks) {
|
|
|
const errors: ContentCheckError[] = [];
|
|
|
if (typeof check === 'string') {
|
|
|
@@ -202,11 +203,13 @@ export class HttpCheckController {
|
|
|
return [];
|
|
|
}
|
|
|
}
|
|
|
+ Logger.debug(`[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 ...`);
|
|
|
for (const con of check.and) {
|
|
|
try {
|
|
|
if (typeof con === 'string') {
|
|
|
@@ -222,15 +225,17 @@ export class HttpCheckController {
|
|
|
} else throw error;
|
|
|
}
|
|
|
}
|
|
|
+ Logger.debug(`[DEBUG] Ran through conjunctive checks, collected ${errorBuffer.length} errors`);
|
|
|
return errorBuffer;
|
|
|
}
|
|
|
|
|
|
- private async doCheck(check: string, responseText: string) {
|
|
|
+ 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`);
|
|
|
throw { type: 'contentCheck', status: HttpCheckStatus.CheckFailed, message: `Regular expression /${check}/i not found in response` };
|
|
|
}
|
|
|
+ Logger.debug(`[DEBUG] RegExp check /${check}/i successful ✔︎`);
|
|
|
}
|
|
|
|
|
|
async close() {
|