code wiki / (root) / nx_http_health.nx

nx_http_health.nx source

↩ module page · 31 lines · 1751 B

1// nx_http_health.nx -- probe a live URL for REAL: HTTP 200 + a real body (+ optional expected content), via an 2// actual sovereign HTTPS GET. This is the honest answer the port-bind/exit-0/gate-log checks couldn't give. 3// argv[1]=url argv[2]=expect_token(optional). exit 0 = healthy (page loaded), 1 = UNHEALTHY. license_tier: ORIGINAL 4import "nx_http_health_lib.nx" 5const K_MAGIC_16384: i64 = 16384 6const K_MAGIC_16380: i64 = 16380 7const K_MAGIC_262144: i64 = 262144 8const K_MAGIC_262140: i64 = 262140 9 10func main(argc: i64, argv: *i64) -> i64 { 11 var url: *u8 = "https://nishifamily.com" as *u8 12 if argc >= 2 { url = argv[1] as *u8 } 13 // ONE fetch, ONE parse, verdict from the same parse (so the display and the verdict can never disagree). 14 let args: *i64 = sys_mmap(16) as *i64; args[0] = url as i64 15 dep_run_capture("_offc/nx_research_fetch.elf" as *u8, args, 1, "/tmp/hh_probe.out" as *u8) 16 let ob: *u8 = sys_mmap(K_MAGIC_16384) 17 let on: i64 = dp_read("/tmp/hh_probe.out" as *u8, ob, K_MAGIC_16380) 18 let st: i64 = hh_after(ob, on, "status=" as *u8) 19 let bb: i64 = hh_after(ob, on, "body_bytes=" as *u8) 20 let body: *u8 = sys_mmap(K_MAGIC_262144) 21 let bn: i64 = dp_read("knowledge/fetched/srch_latest.raw" as *u8, body, K_MAGIC_262140) 22 var h: i64 = 1 23 if st != 200 { h = 0 } 24 if bb <= 0 { h = 0 } 25 if argc >= 3 { if dp_contains(body, bn, argv[2] as *u8) == 0 { h = 0 } } 26 dp_w(1, "HTTP-HEALTH url=" as *u8); dp_w(1, url); dp_w(1, " http_status=" as *u8); dp_wn(1, st) 27 dp_w(1, " body_bytes=" as *u8); dp_wn(1, bb); dp_w(1, " healthy=" as *u8); dp_wn(1, h) 28 dp_w(1, " (REAL GET -- not a port-bind/exit-0 proxy)\n" as *u8) 29 if h == 1 { sys_exit(0); return 0 } 30 sys_exit(1); return 1 31}