31 lines
919 B
Python
31 lines
919 B
Python
#!/usr/bin/env python3
|
|
"""Production-style gateway-only agent: catalog read every 5 minutes."""
|
|
import json, time, urllib.request
|
|
from pathlib import Path
|
|
|
|
BASE = "http://127.0.0.1:9137"
|
|
LOG = Path("/var/lib/agent-gw/agent.log")
|
|
|
|
|
|
def call(tool):
|
|
with urllib.request.urlopen(BASE + "/v1/call?tool=" + tool, timeout=10) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
|
|
def main():
|
|
LOG.parent.mkdir(parents=True, exist_ok=True)
|
|
while True:
|
|
try:
|
|
d = call("catalog.read")
|
|
with LOG.open("a") as f:
|
|
f.write(json.dumps({"ts": time.time(), "tool": "catalog.read",
|
|
"bytes": len(d.get("body") or "")}) + "\n")
|
|
except Exception as e:
|
|
with LOG.open("a") as f:
|
|
f.write(json.dumps({"ts": time.time(), "error": str(e)[:200]}) + "\n")
|
|
time.sleep(300)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|