diff --git a/CLAUDE.md b/CLAUDE.md index 5b1fb6a..94f8a3a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,7 +31,7 @@ pip install -r requirements.txt python kao.py ``` -UI available at http://localhost:5000 +UI available at http://localhost:5100 ## Configuration @@ -39,7 +39,7 @@ Edit `config.json` to configure detectors: ```json { - "aggregator_url": "http://localhost:5000", + "aggregator_url": "http://localhost:5100", "aggregator": { "script": "aggregator.py" }, "detectors": [ { diff --git a/README.md b/README.md index 6ba6469..16a3fbf 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ pip install -r requirements.txt python kao.py ``` -Open http://localhost:5000 on your phone (use Fully Kiosk Browser for best results). +Open http://localhost:5100 on your phone (use Fully Kiosk Browser for best results). ## Status Faces @@ -59,7 +59,7 @@ Edit `config.json` to enable/disable detectors and set thresholds: ```json { - "aggregator_url": "http://localhost:5000", + "aggregator_url": "http://localhost:5100", "detectors": [ { "name": "disk_space", @@ -80,7 +80,7 @@ Edit `config.json` to enable/disable detectors and set thresholds: Create your own detector by POSTing events to the aggregator: ```bash -curl -X POST http://localhost:5000/event \ +curl -X POST http://localhost:5100/event \ -H "Content-Type: application/json" \ -d '{"id": "my_check", "priority": 2, "message": "Something is wrong", "ttl": 120}' ``` @@ -92,7 +92,7 @@ curl -X POST http://localhost:5000/event \ Clear an event: ```bash -curl -X POST http://localhost:5000/clear \ +curl -X POST http://localhost:5100/clear \ -d '{"id": "my_check"}' ``` @@ -103,10 +103,10 @@ Add webhook commands to your Home Assistant config: ```yaml rest_command: sentry_sleep: - url: "http://YOUR_SERVER:5000/sleep" + url: "http://YOUR_SERVER:5100/sleep" method: POST sentry_wake: - url: "http://YOUR_SERVER:5000/wake" + url: "http://YOUR_SERVER:5100/wake" method: POST ``` diff --git a/aggregator.py b/aggregator.py index 1160aff..6002fe0 100644 --- a/aggregator.py +++ b/aggregator.py @@ -4,6 +4,7 @@ A lightweight event broker that manages priority-based system status. """ import json +import os import random import threading import time @@ -252,6 +253,8 @@ def list_events(): def main(): + port = int(os.environ.get("PORT", 5100)) + # Write initial optimal state write_status() print(f"Status file: {STATUS_FILE}") @@ -261,7 +264,7 @@ def main(): cleanup_thread.start() # Run Flask - app.run(host="0.0.0.0", port=5000, threaded=True) + app.run(host="0.0.0.0", port=port, threaded=True) if __name__ == "__main__": diff --git a/config.json b/config.json index 60841db..41587f7 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "aggregator_url": "http://localhost:5000", + "port": 5100, "aggregator": { "script": "aggregator.py" }, diff --git a/install.sh b/install.sh index 4155337..a30a172 100644 --- a/install.sh +++ b/install.sh @@ -68,7 +68,7 @@ echo "====================================" echo " Installation complete!" echo "====================================" echo "" -echo "Kao is now running at http://$(hostname -I | awk '{print $1}'):5000" +echo "Kao is now running at http://$(hostname -I | awk '{print $1}'):5100" echo "" echo "Commands:" echo " sudo systemctl status kao # Check status" diff --git a/kao.py b/kao.py index edb5290..d98a4df 100644 --- a/kao.py +++ b/kao.py @@ -89,11 +89,17 @@ class KaoManager: break print(f"[{name}] {line.rstrip()}") + def get_aggregator_url(self): + """Get aggregator URL from config port.""" + port = self.config.get("port", 5100) + return f"http://localhost:{port}" + def start_aggregator(self): """Start the aggregator service.""" agg_config = self.config.get("aggregator", {}) script = agg_config.get("script", "aggregator.py") env = agg_config.get("env", {}) + env["PORT"] = str(self.config.get("port", 5100)) process = self.start_process("aggregator", script, env) if process: @@ -102,13 +108,12 @@ class KaoManager: "config": {"name": "aggregator", "script": script, "env": env}, } # Wait for aggregator to be ready - url = self.config.get("aggregator_url", "http://localhost:5000") - return self.wait_for_aggregator(url) + return self.wait_for_aggregator(self.get_aggregator_url()) return False def start_detectors(self): """Start all enabled detectors.""" - url = self.config.get("aggregator_url", "http://localhost:5000") + url = self.get_aggregator_url() for detector in self.config.get("detectors", []): if not detector.get("enabled", True): @@ -140,7 +145,7 @@ class KaoManager: if self.running: config = info["config"] - env = {"AGGREGATOR_URL": self.config.get("aggregator_url", "http://localhost:5000")} + env = {"AGGREGATOR_URL": self.get_aggregator_url()} env.update(config.get("env", {})) new_process = self.start_process(name, config["script"], env) @@ -186,7 +191,7 @@ class KaoManager: print(" Kao") print("=" * 50) print(f"Config: {self.config_path}") - print(f"Aggregator URL: {self.config.get('aggregator_url')}") + print(f"Port: {self.config.get('port', 5100)}") print() enabled = [d["name"] for d in self.config.get("detectors", []) if d.get("enabled", True)] @@ -211,7 +216,7 @@ class KaoManager: print() print("=" * 50) - print(f" UI available at: {self.config.get('aggregator_url')}") + print(f" UI available at: {self.get_aggregator_url()}") print("=" * 50) print()