feat(tcs): establish five-domain mother brain runtime
This commit is contained in:
parent
828fa0b8e2
commit
55a4d77248
29 changed files with 904 additions and 12 deletions
|
|
@ -37,8 +37,19 @@ async function check(target) {
|
|||
const timer = setTimeout(() => controller.abort(), target.timeout_ms || 8000);
|
||||
try {
|
||||
const response = await fetch(target.url, { method: "GET", redirect: "manual", signal: controller.signal, headers: { "user-agent": "Guanghu-State-Change-Sentinel/1.0" } });
|
||||
const ok = (target.accept || [200]).includes(response.status);
|
||||
return { ok, detail: `HTTP ${response.status}`, observed_at: new Date().toISOString() };
|
||||
let ok = (target.accept || [200]).includes(response.status);
|
||||
let detail = `HTTP ${response.status}`;
|
||||
if (target.json_expect && response.headers.get("content-type")?.includes("application/json")) {
|
||||
const body = await response.json();
|
||||
for (const [field, expected] of Object.entries(target.json_expect)) {
|
||||
const observed = field.split(".").reduce((value, key) => value && value[key], body);
|
||||
if (observed !== expected) {
|
||||
ok = false;
|
||||
detail += ` ${field}=${JSON.stringify(observed)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { ok, detail, observed_at: new Date().toISOString() };
|
||||
} catch (error) {
|
||||
return { ok: false, detail: error.name === "AbortError" ? "timeout" : "connection-failed", observed_at: new Date().toISOString() };
|
||||
} finally { clearTimeout(timer); }
|
||||
|
|
|
|||
Loading…
Reference in a new issue