Increase OpenWrt SSH timeouts
This commit is contained in:
@@ -207,10 +207,12 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
|
|
||||||
async def _ssh_cmd(cmd: str) -> tuple[int, str]:
|
async def _ssh_cmd(cmd: str) -> tuple[int, str]:
|
||||||
run = ssh_cmd + ["sh", "-c", cmd]
|
run = ssh_cmd + ["sh", "-c", cmd]
|
||||||
return await run_cmd(run, timeout=timeout_sec + 5)
|
return await run_cmd(run, timeout=timeout_sec + 15)
|
||||||
|
|
||||||
sys_info = None
|
sys_info = None
|
||||||
rc, out = await _ssh_cmd("ubus call system info 2>/dev/null")
|
rc, out = await _ssh_cmd("ubus call system info 2>/dev/null")
|
||||||
|
if rc == 124:
|
||||||
|
return "⚠️ OpenWrt SSH error (system info): timeout"
|
||||||
if rc == 0 and out.strip():
|
if rc == 0 and out.strip():
|
||||||
try:
|
try:
|
||||||
sys_info = json.loads(out)
|
sys_info = json.loads(out)
|
||||||
@@ -218,6 +220,8 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
sys_info = None
|
sys_info = None
|
||||||
if sys_info is None:
|
if sys_info is None:
|
||||||
rc_u, out_u = await _ssh_cmd("cat /proc/uptime; echo; cat /proc/loadavg")
|
rc_u, out_u = await _ssh_cmd("cat /proc/uptime; echo; cat /proc/loadavg")
|
||||||
|
if rc_u == 124:
|
||||||
|
return "⚠️ OpenWrt SSH error (uptime/load): timeout"
|
||||||
if rc_u != 0:
|
if rc_u != 0:
|
||||||
return f"⚠️ OpenWrt SSH error: {out_u.strip() or 'unknown error'}"
|
return f"⚠️ OpenWrt SSH error: {out_u.strip() or 'unknown error'}"
|
||||||
fallback_raw = out_u
|
fallback_raw = out_u
|
||||||
@@ -225,6 +229,8 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
fallback_raw = ""
|
fallback_raw = ""
|
||||||
|
|
||||||
rc, out = await _ssh_cmd("ubus call network.interface.wan status 2>/dev/null")
|
rc, out = await _ssh_cmd("ubus call network.interface.wan status 2>/dev/null")
|
||||||
|
if rc == 124:
|
||||||
|
return "⚠️ OpenWrt SSH error (wan status): timeout"
|
||||||
if rc == 0 and out.strip():
|
if rc == 0 and out.strip():
|
||||||
try:
|
try:
|
||||||
wan_status = json.loads(out)
|
wan_status = json.loads(out)
|
||||||
@@ -234,6 +240,8 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
wan_status = {}
|
wan_status = {}
|
||||||
|
|
||||||
rc, out = await _ssh_cmd("ubus call network.wireless status 2>/dev/null")
|
rc, out = await _ssh_cmd("ubus call network.wireless status 2>/dev/null")
|
||||||
|
if rc == 124:
|
||||||
|
return "⚠️ OpenWrt SSH error (wireless status): timeout"
|
||||||
if rc == 0 and out.strip():
|
if rc == 0 and out.strip():
|
||||||
try:
|
try:
|
||||||
wireless = json.loads(out)
|
wireless = json.loads(out)
|
||||||
@@ -243,6 +251,8 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
wireless = {}
|
wireless = {}
|
||||||
|
|
||||||
rc, out = await _ssh_cmd("ubus call luci-rpc getDHCPLeases '{\"family\":4}' 2>/dev/null")
|
rc, out = await _ssh_cmd("ubus call luci-rpc getDHCPLeases '{\"family\":4}' 2>/dev/null")
|
||||||
|
if rc == 124:
|
||||||
|
return "⚠️ OpenWrt SSH error (dhcp leases): timeout"
|
||||||
if rc == 0 and out.strip():
|
if rc == 0 and out.strip():
|
||||||
try:
|
try:
|
||||||
leases = json.loads(out)
|
leases = json.loads(out)
|
||||||
@@ -251,6 +261,8 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
else:
|
else:
|
||||||
leases = None
|
leases = None
|
||||||
rc_l, out_l = await _ssh_cmd("cat /tmp/dhcp.leases 2>/dev/null || true")
|
rc_l, out_l = await _ssh_cmd("cat /tmp/dhcp.leases 2>/dev/null || true")
|
||||||
|
if rc_l == 124:
|
||||||
|
return "⚠️ OpenWrt SSH error (leases fallback): timeout"
|
||||||
if rc_l == 0:
|
if rc_l == 0:
|
||||||
leases_fallback = out_l
|
leases_fallback = out_l
|
||||||
else:
|
else:
|
||||||
@@ -276,7 +288,9 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
|||||||
"-c",
|
"-c",
|
||||||
f"ubus call hostapd.{ifname} get_clients 2>/dev/null || echo '{{}}'",
|
f"ubus call hostapd.{ifname} get_clients 2>/dev/null || echo '{{}}'",
|
||||||
]
|
]
|
||||||
rc2, out2 = await run_cmd(cmd_clients, timeout=timeout_sec + 5)
|
rc2, out2 = await run_cmd(cmd_clients, timeout=timeout_sec + 15)
|
||||||
|
if rc2 == 124:
|
||||||
|
return f"⚠️ OpenWrt SSH error (wifi clients {ifname}): timeout"
|
||||||
if rc2 == 0 and out2.strip():
|
if rc2 == 0 and out2.strip():
|
||||||
wifi_clients.extend(_parse_hostapd_clients(out2.strip(), ifname))
|
wifi_clients.extend(_parse_hostapd_clients(out2.strip(), ifname))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user