Make port configurable (default 5100)
- Port now set via config.json "port" field - Aggregator reads PORT from environment variable - Updated all docs and scripts to use port 5100 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,7 @@ pip install -r requirements.txt
|
|||||||
python kao.py
|
python kao.py
|
||||||
```
|
```
|
||||||
|
|
||||||
UI available at http://localhost:5000
|
UI available at http://localhost:5100
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ Edit `config.json` to configure detectors:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"aggregator_url": "http://localhost:5000",
|
"aggregator_url": "http://localhost:5100",
|
||||||
"aggregator": { "script": "aggregator.py" },
|
"aggregator": { "script": "aggregator.py" },
|
||||||
"detectors": [
|
"detectors": [
|
||||||
{
|
{
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -30,7 +30,7 @@ pip install -r requirements.txt
|
|||||||
python kao.py
|
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
|
## Status Faces
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ Edit `config.json` to enable/disable detectors and set thresholds:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"aggregator_url": "http://localhost:5000",
|
"aggregator_url": "http://localhost:5100",
|
||||||
"detectors": [
|
"detectors": [
|
||||||
{
|
{
|
||||||
"name": "disk_space",
|
"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:
|
Create your own detector by POSTing events to the aggregator:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:5000/event \
|
curl -X POST http://localhost:5100/event \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"id": "my_check", "priority": 2, "message": "Something is wrong", "ttl": 120}'
|
-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:
|
Clear an event:
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:5000/clear \
|
curl -X POST http://localhost:5100/clear \
|
||||||
-d '{"id": "my_check"}'
|
-d '{"id": "my_check"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -103,10 +103,10 @@ Add webhook commands to your Home Assistant config:
|
|||||||
```yaml
|
```yaml
|
||||||
rest_command:
|
rest_command:
|
||||||
sentry_sleep:
|
sentry_sleep:
|
||||||
url: "http://YOUR_SERVER:5000/sleep"
|
url: "http://YOUR_SERVER:5100/sleep"
|
||||||
method: POST
|
method: POST
|
||||||
sentry_wake:
|
sentry_wake:
|
||||||
url: "http://YOUR_SERVER:5000/wake"
|
url: "http://YOUR_SERVER:5100/wake"
|
||||||
method: POST
|
method: POST
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ A lightweight event broker that manages priority-based system status.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@@ -252,6 +253,8 @@ def list_events():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
port = int(os.environ.get("PORT", 5100))
|
||||||
|
|
||||||
# Write initial optimal state
|
# Write initial optimal state
|
||||||
write_status()
|
write_status()
|
||||||
print(f"Status file: {STATUS_FILE}")
|
print(f"Status file: {STATUS_FILE}")
|
||||||
@@ -261,7 +264,7 @@ def main():
|
|||||||
cleanup_thread.start()
|
cleanup_thread.start()
|
||||||
|
|
||||||
# Run Flask
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"aggregator_url": "http://localhost:5000",
|
"port": 5100,
|
||||||
"aggregator": {
|
"aggregator": {
|
||||||
"script": "aggregator.py"
|
"script": "aggregator.py"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ echo "===================================="
|
|||||||
echo " Installation complete!"
|
echo " Installation complete!"
|
||||||
echo "===================================="
|
echo "===================================="
|
||||||
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 ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " sudo systemctl status kao # Check status"
|
echo " sudo systemctl status kao # Check status"
|
||||||
|
|||||||
17
kao.py
17
kao.py
@@ -89,11 +89,17 @@ class KaoManager:
|
|||||||
break
|
break
|
||||||
print(f"[{name}] {line.rstrip()}")
|
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):
|
def start_aggregator(self):
|
||||||
"""Start the aggregator service."""
|
"""Start the aggregator service."""
|
||||||
agg_config = self.config.get("aggregator", {})
|
agg_config = self.config.get("aggregator", {})
|
||||||
script = agg_config.get("script", "aggregator.py")
|
script = agg_config.get("script", "aggregator.py")
|
||||||
env = agg_config.get("env", {})
|
env = agg_config.get("env", {})
|
||||||
|
env["PORT"] = str(self.config.get("port", 5100))
|
||||||
|
|
||||||
process = self.start_process("aggregator", script, env)
|
process = self.start_process("aggregator", script, env)
|
||||||
if process:
|
if process:
|
||||||
@@ -102,13 +108,12 @@ class KaoManager:
|
|||||||
"config": {"name": "aggregator", "script": script, "env": env},
|
"config": {"name": "aggregator", "script": script, "env": env},
|
||||||
}
|
}
|
||||||
# Wait for aggregator to be ready
|
# Wait for aggregator to be ready
|
||||||
url = self.config.get("aggregator_url", "http://localhost:5000")
|
return self.wait_for_aggregator(self.get_aggregator_url())
|
||||||
return self.wait_for_aggregator(url)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def start_detectors(self):
|
def start_detectors(self):
|
||||||
"""Start all enabled detectors."""
|
"""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", []):
|
for detector in self.config.get("detectors", []):
|
||||||
if not detector.get("enabled", True):
|
if not detector.get("enabled", True):
|
||||||
@@ -140,7 +145,7 @@ class KaoManager:
|
|||||||
|
|
||||||
if self.running:
|
if self.running:
|
||||||
config = info["config"]
|
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", {}))
|
env.update(config.get("env", {}))
|
||||||
|
|
||||||
new_process = self.start_process(name, config["script"], env)
|
new_process = self.start_process(name, config["script"], env)
|
||||||
@@ -186,7 +191,7 @@ class KaoManager:
|
|||||||
print(" Kao")
|
print(" Kao")
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
print(f"Config: {self.config_path}")
|
print(f"Config: {self.config_path}")
|
||||||
print(f"Aggregator URL: {self.config.get('aggregator_url')}")
|
print(f"Port: {self.config.get('port', 5100)}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
enabled = [d["name"] for d in self.config.get("detectors", []) if d.get("enabled", True)]
|
enabled = [d["name"] for d in self.config.get("detectors", []) if d.get("enabled", True)]
|
||||||
@@ -211,7 +216,7 @@ class KaoManager:
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
print(f" UI available at: {self.config.get('aggregator_url')}")
|
print(f" UI available at: {self.get_aggregator_url()}")
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user