mirror of
https://github.com/andrey271192/vps_monitoring.git
synced 2026-09-21 12:01:58 +00:00
fix(keenetic): preserve URL scheme/ports and IPv4 polling
Use web_url scheme and host:port for API base URL instead of forcing https. Force IPv4 in aiohttp to avoid IPv6 hangs on KeenDNS. Sync canonical 24-router list with Russian names. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -36,7 +36,7 @@ async def main():
|
||||
for d in devices:
|
||||
r = await check(d)
|
||||
print(f"{d['name']:22} {r}")
|
||||
await asyncio.sleep(0.3)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
48
scripts/quick_auth_check.py
Normal file
48
scripts/quick_auth_check.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fast auth-only check for all routers (no RCI batch)."""
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
from server.services.keenetic_client import KeeneticClient
|
||||
|
||||
DATA = Path("/opt/vps-monitoring/data/keenetic.json")
|
||||
|
||||
|
||||
async def one(dev):
|
||||
c = KeeneticClient(
|
||||
host=dev.get("host", ""),
|
||||
login=dev.get("login", "admin"),
|
||||
password=dev.get("password", ""),
|
||||
web_url=dev.get("web_url", ""),
|
||||
)
|
||||
try:
|
||||
ok = await c.authenticate()
|
||||
if ok:
|
||||
return "ONLINE"
|
||||
return f"OFFLINE: {c.last_error}"
|
||||
except Exception as e:
|
||||
return f"ERR: {e}"
|
||||
finally:
|
||||
await c.close()
|
||||
|
||||
|
||||
async def main():
|
||||
with open(DATA) as f:
|
||||
devices = json.load(f)
|
||||
online = 0
|
||||
for d in devices:
|
||||
r = await one(d)
|
||||
if r == "ONLINE":
|
||||
online += 1
|
||||
name = d["name"]
|
||||
url = d.get("web_url", "")
|
||||
print(f"{name:28} {r:40} {url}")
|
||||
await asyncio.sleep(0.3)
|
||||
print(f"\nTotal: {online}/{len(devices)} ONLINE")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1,12 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Sync keenetic.json with canonical import list (names, web_url, anydesk)."""
|
||||
"""Sync keenetic.json with canonical router list (24 entries, exact URLs)."""
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
# Authoritative list: Russian name, exact web URL, AnyDesk (optional)
|
||||
IMPORT = [
|
||||
("Москва Сити Асланян", "https://moscowcity.netcraze.pro:5443", ""),
|
||||
("Вымпел Асланян", "https://vimpel.netcraze.link", ""),
|
||||
("Асланян Квартира", "https://eropkinskii.netcraze.club", ""),
|
||||
("Новоглаголево Лилиана", "http://91.77.164.164", ""),
|
||||
("Лилиана Фотиева", "https://fotieva.netcraze.link", ""),
|
||||
("Лилиана Лофт", "https://loftliliana.netcraze.pro", "1020687391"),
|
||||
("Артем vtb126", "https://vtb126.netcraze.club", ""),
|
||||
("Артем Квартира Подмосковный", "http://95.165.93.46:777", "1527495291"),
|
||||
@@ -43,9 +49,6 @@ def host_from_url(url: str) -> str:
|
||||
return parsed.netloc or url.replace("https://", "").replace("http://", "").rstrip("/")
|
||||
|
||||
|
||||
IMPORT_HOSTS = {host_from_url(url) for _, url, _ in IMPORT}
|
||||
|
||||
|
||||
def make_device(name, keenetic_url, login, password, anydesk="", added=None):
|
||||
keenetic_url = normalize_web_url(keenetic_url)
|
||||
host = host_from_url(keenetic_url)
|
||||
@@ -64,6 +67,7 @@ def sync_file(path: Path, default_password: str):
|
||||
with open(path) as f:
|
||||
old = json.load(f)
|
||||
|
||||
by_name = {d.get("name", ""): d for d in old}
|
||||
by_host = {d.get("host", ""): d for d in old}
|
||||
path.with_suffix(".json.bak").write_text(
|
||||
json.dumps(old, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
@@ -72,25 +76,14 @@ def sync_file(path: Path, default_password: str):
|
||||
result = []
|
||||
for name, url, ad in IMPORT:
|
||||
host = host_from_url(url)
|
||||
prev = by_host.get(host, {})
|
||||
prev = by_name.get(name) or by_host.get(host, {})
|
||||
login = prev.get("login", "admin")
|
||||
password = prev.get("password") or default_password
|
||||
added = prev.get("added")
|
||||
result.append(make_device(name, url, login, password, ad, added))
|
||||
|
||||
for d in old:
|
||||
host = d.get("host", "")
|
||||
if host in IMPORT_HOSTS:
|
||||
continue
|
||||
if not d.get("web_url") and host:
|
||||
h = host
|
||||
d["web_url"] = normalize_web_url(
|
||||
h if h.startswith("http") else ("http://" if h[0].isdigit() else "https://") + h
|
||||
)
|
||||
result.append(d)
|
||||
|
||||
path.write_text(json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
print(f"Wrote {len(result)} devices ({len(IMPORT)} import + {len(result) - len(IMPORT)} extra)")
|
||||
print(f"Wrote {len(result)} devices (canonical import)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user