Compare commits
10 Commits
326658ed26
...
v1.4.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bea6ca4ea | |||
|
|
d2a8c2d928 | ||
|
|
3303e22843 | ||
| 2456fd0ee8 | |||
|
|
d2fd3b7182 | ||
|
|
1d94c5dd04 | ||
|
|
814b6f915e | ||
|
|
9cfdebe553 | ||
|
|
f773e1dac9 | ||
| c133932b29 |
26
CHANGELOG.md
26
CHANGELOG.md
@@ -6,6 +6,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.4.2] - 2026-03-17
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Tray icon color now reflects watcher + API health rather than unit ages — green=API OK, amber=API disabled, red=API failing, purple=watcher error.
|
||||||
|
- Status menu text updated to show `Running — API OK | N unit(s) | scan Xm ago`.
|
||||||
|
- Units submenu removed from tray — status tracking for individual units is handled by terra-view, not the watcher.
|
||||||
|
- Unit list still logged to console and log file for debugging, but no OK/Pending/Missing judgement applied.
|
||||||
|
- `watcher_status` field added to heartbeat payload so terra-view receives accurate watcher health data.
|
||||||
|
|
||||||
|
## [1.4.1] - 2026-03-17
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `config.ini` now saves to `AppData\Local\Series3Watcher\` instead of `Program Files` — fixes permission denied error on first-run wizard save.
|
||||||
|
- Config path resolution in both `series3_tray.py` and `series3_watcher.py` updated to use `sys.frozen` + `LOCALAPPDATA` when running as a PyInstaller `.exe`.
|
||||||
|
- Status menu item now uses a callable so it updates every time the menu opens — was showing stale "Starting..." while tooltip correctly showed current status.
|
||||||
|
- Settings dialog now opens in its own thread — fixes unresponsive tabs and text fields while the watcher loop is running.
|
||||||
|
- Tray icon reverted to plain colored dot — custom icon graphic was unreadable at 16px tray size. `.ico` file is still used for the `.exe` file icon.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Terra-View URL field in settings wizard now accepts base URL only (e.g. `http://192.168.x.x:8000`) — `/api/series3/heartbeat` endpoint appended automatically.
|
||||||
|
- Test Connection button now hits `/health` endpoint instead of posting a fake heartbeat — no database side effects.
|
||||||
|
- "terra-view URL" label capitalized to "Terra-View URL".
|
||||||
|
- Default log path updated to `AppData\Local\Series3Watcher\agent_logs\series3_watcher.log`.
|
||||||
|
- Installer now creates `agent_logs\` folder on install.
|
||||||
|
- `BUILDING.md` added — step-by-step guide for building, releasing, and updating.
|
||||||
|
|
||||||
## [1.4.0] - 2026-03-12
|
## [1.4.0] - 2026-03-12
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Series 3 Watcher v1.4.1
|
# Series 3 Watcher v1.4.2
|
||||||
|
|
||||||
Monitors Instantel **Series 3 (Minimate)** call-in activity on a Blastware server. Runs as a **system tray app** that starts automatically on login, reports heartbeats to terra-view, and self-updates from Gitea.
|
Monitors Instantel **Series 3 (Minimate)** call-in activity on a Blastware server. Runs as a **system tray app** that starts automatically on login, reports heartbeats to terra-view, and self-updates from Gitea.
|
||||||
|
|
||||||
@@ -82,7 +82,6 @@ All settings live in `config.ini`. The Setup Wizard covers every field, but here
|
|||||||
|-----|-------------|
|
|-----|-------------|
|
||||||
| `ENABLE_LOGGING` | `true` / `false` |
|
| `ENABLE_LOGGING` | `true` / `false` |
|
||||||
| `LOG_RETENTION_DAYS` | Auto-clear log after this many days (default `30`) |
|
| `LOG_RETENTION_DAYS` | Auto-clear log after this many days (default `30`) |
|
||||||
| `COLORIZE` | ANSI colours in console — leave `false` on Win7 |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -117,7 +116,7 @@ To view connected watchers: **Settings → Developer → Watcher Manager**.
|
|||||||
|
|
||||||
## Versioning
|
## Versioning
|
||||||
|
|
||||||
Follows **Semantic Versioning**. Current release: **v1.4.1**.
|
Follows **Semantic Versioning**. Current release: **v1.4.2**.
|
||||||
See `CHANGELOG.md` for full history.
|
See `CHANGELOG.md` for full history.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
# Series 3 Watcher — v1_0(py38-safe) for DL2
|
|
||||||
|
|
||||||
**Target**: Windows 7 + Python 3.8.10
|
|
||||||
**Baseline**: v5_4 (no logic changes)
|
|
||||||
|
|
||||||
## Files
|
|
||||||
- series3_agent_v1_0_py38.py — main script (py38-safe)
|
|
||||||
- config.ini — your config (already included)
|
|
||||||
- series3_roster.csv — your roster (already included, this auto updates from a URL to a dropbox file)
|
|
||||||
- requirements.txt — none beyond stdlib
|
|
||||||
|
|
||||||
## Install
|
|
||||||
1) Create `C:\SeismoEmitter\` on DL2
|
|
||||||
2) Extract this ZIP into that folder
|
|
||||||
3) Open CMD:
|
|
||||||
```cmd
|
|
||||||
cd C:\SeismoEmitter
|
|
||||||
python series3_agent_v1_0_py38.py
|
|
||||||
```
|
|
||||||
(If the console shows escape codes on Win7, set `COLORIZE = False` in `config.ini`.)
|
|
||||||
|
|
||||||
## Quick validation
|
|
||||||
- Heartbeat prints Local/UTC timestamps
|
|
||||||
- One line per active roster unit with OK/Pending/Missing, Age, Last, File
|
|
||||||
- Unexpected units block shows .MLG not in roster
|
|
||||||
- agent.log rotates per LOG_RETENTION_DAYS
|
|
||||||
@@ -22,9 +22,6 @@ ENABLE_LOGGING = True
|
|||||||
LOG_FILE = C:\Users\%USERNAME%\AppData\Local\Series3Watcher\agent_logs\series3_watcher.log
|
LOG_FILE = C:\Users\%USERNAME%\AppData\Local\Series3Watcher\agent_logs\series3_watcher.log
|
||||||
LOG_RETENTION_DAYS = 30
|
LOG_RETENTION_DAYS = 30
|
||||||
|
|
||||||
# Console colors - (Doesn't work on windows 7)
|
|
||||||
COLORIZE = FALSE
|
|
||||||
|
|
||||||
# .MLG parsing
|
# .MLG parsing
|
||||||
MLG_HEADER_BYTES = 2048 ; used for unit-id extraction
|
MLG_HEADER_BYTES = 2048 ; used for unit-id extraction
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[Setup]
|
[Setup]
|
||||||
AppName=Series 3 Watcher
|
AppName=Series 3 Watcher
|
||||||
AppVersion=1.4.1
|
AppVersion=1.4.2
|
||||||
AppPublisher=Terra-Mechanics Inc.
|
AppPublisher=Terra-Mechanics Inc.
|
||||||
DefaultDirName={pf}\Series3Watcher
|
DefaultDirName={pf}\Series3Watcher
|
||||||
DefaultGroupName=Series 3 Watcher
|
DefaultGroupName=Series 3 Watcher
|
||||||
|
|||||||
127
series3_tray.py
127
series3_tray.py
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Series 3 Watcher — System Tray Launcher v1.4.1
|
Series 3 Watcher — System Tray Launcher v1.4.2
|
||||||
Requires: pystray, Pillow, tkinter (stdlib)
|
Requires: pystray, Pillow, tkinter (stdlib)
|
||||||
|
|
||||||
Run with: pythonw series3_tray.py (no console window)
|
Run with: pythonw series3_tray.py (no console window)
|
||||||
@@ -154,50 +154,11 @@ COLORS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ICON_SIZE = 64
|
ICON_SIZE = 64
|
||||||
ICON_FILE = os.path.join(HERE, "icon.ico")
|
|
||||||
|
|
||||||
# Load base icon once at startup; fall back to None if missing.
|
|
||||||
# When frozen, bundled data files live in sys._MEIPASS.
|
|
||||||
def _load_base_icon():
|
|
||||||
candidates = [ICON_FILE]
|
|
||||||
if getattr(sys, "frozen", False):
|
|
||||||
candidates.insert(0, os.path.join(sys._MEIPASS, "icon.ico"))
|
|
||||||
for path in candidates:
|
|
||||||
try:
|
|
||||||
img = Image.open(path)
|
|
||||||
img = img.convert("RGBA").resize((ICON_SIZE, ICON_SIZE), Image.LANCZOS)
|
|
||||||
return img
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
return None
|
|
||||||
|
|
||||||
_BASE_ICON = _load_base_icon()
|
|
||||||
|
|
||||||
|
|
||||||
def make_icon(status):
|
def make_icon(status):
|
||||||
"""
|
"""Draw a plain colored circle for the system tray — clean and readable at 16px."""
|
||||||
Use icon.ico as the base and overlay a small status dot in the
|
|
||||||
bottom-right corner. Falls back to a plain colored circle if the
|
|
||||||
ico file is not available.
|
|
||||||
"""
|
|
||||||
color = COLORS.get(status, COLORS["starting"])
|
color = COLORS.get(status, COLORS["starting"])
|
||||||
|
|
||||||
if _BASE_ICON is not None:
|
|
||||||
img = _BASE_ICON.copy()
|
|
||||||
draw = ImageDraw.Draw(img)
|
|
||||||
# Dot size and position — bottom-right corner
|
|
||||||
dot_r = ICON_SIZE // 5 # radius ~12px on 64px icon
|
|
||||||
margin = 2
|
|
||||||
x0 = ICON_SIZE - dot_r * 2 - margin
|
|
||||||
y0 = ICON_SIZE - dot_r * 2 - margin
|
|
||||||
x1 = ICON_SIZE - margin
|
|
||||||
y1 = ICON_SIZE - margin
|
|
||||||
# White outline for contrast on dark/light backgrounds
|
|
||||||
draw.ellipse([x0 - 2, y0 - 2, x1 + 2, y1 + 2], fill=(255, 255, 255, 220))
|
|
||||||
draw.ellipse([x0, y0, x1, y1], fill=color + (255,))
|
|
||||||
return img
|
|
||||||
|
|
||||||
# Fallback: plain colored circle
|
|
||||||
img = Image.new("RGBA", (ICON_SIZE, ICON_SIZE), (0, 0, 0, 0))
|
img = Image.new("RGBA", (ICON_SIZE, ICON_SIZE), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
margin = 6
|
margin = 6
|
||||||
@@ -285,15 +246,13 @@ class WatcherTray:
|
|||||||
# --- Menu item callbacks ---
|
# --- Menu item callbacks ---
|
||||||
|
|
||||||
def _open_settings(self, icon, item):
|
def _open_settings(self, icon, item):
|
||||||
"""Open the settings dialog. On save, restart watcher thread."""
|
"""Open the settings dialog in its own thread so the tray stays responsive."""
|
||||||
|
def _run():
|
||||||
from settings_dialog import show_dialog
|
from settings_dialog import show_dialog
|
||||||
saved = show_dialog(CONFIG_PATH, wizard=False)
|
saved = show_dialog(CONFIG_PATH, wizard=False)
|
||||||
if saved:
|
if saved:
|
||||||
self._restart_watcher()
|
self._restart_watcher()
|
||||||
# Rebuild menu so status label refreshes
|
threading.Thread(target=_run, daemon=True, name="settings-dialog").start()
|
||||||
if self._icon is not None:
|
|
||||||
with self._menu_lock:
|
|
||||||
self._icon.menu = self._build_menu()
|
|
||||||
|
|
||||||
def _open_logs(self, icon, item):
|
def _open_logs(self, icon, item):
|
||||||
log_dir = self.state.get("log_dir")
|
log_dir = self.state.get("log_dir")
|
||||||
@@ -318,50 +277,48 @@ class WatcherTray:
|
|||||||
status = self.state.get("status", "starting")
|
status = self.state.get("status", "starting")
|
||||||
last_err = self.state.get("last_error")
|
last_err = self.state.get("last_error")
|
||||||
last_scan = self.state.get("last_scan")
|
last_scan = self.state.get("last_scan")
|
||||||
|
api_status = self.state.get("api_status", "disabled")
|
||||||
|
unit_count = len(self.state.get("units", []))
|
||||||
|
|
||||||
if status == "error":
|
if status == "error":
|
||||||
return "Status: Error — {}".format(last_err or "unknown")
|
return "Error — {}".format(last_err or "unknown")
|
||||||
if status == "starting":
|
if status == "starting":
|
||||||
return "Status: Starting..."
|
return "Starting..."
|
||||||
|
|
||||||
|
# Scan age
|
||||||
if last_scan is not None:
|
if last_scan is not None:
|
||||||
age_secs = int((datetime.now() - last_scan).total_seconds())
|
age_secs = int((datetime.now() - last_scan).total_seconds())
|
||||||
if age_secs < 60:
|
age_str = "{}s ago".format(age_secs) if age_secs < 60 else "{}m ago".format(age_secs // 60)
|
||||||
age_str = "{}s ago".format(age_secs)
|
|
||||||
else:
|
else:
|
||||||
age_str = "{}m ago".format(age_secs // 60)
|
age_str = "never"
|
||||||
unit_count = len(self.state.get("units", []))
|
|
||||||
return "Status: {} | {} unit(s) | scan {}".format(
|
|
||||||
status.upper(), unit_count, age_str
|
|
||||||
)
|
|
||||||
return "Status: {}".format(status.upper())
|
|
||||||
|
|
||||||
def _build_units_submenu(self):
|
# API status label
|
||||||
units = self.state.get("units", [])
|
if api_status == "ok":
|
||||||
if not units:
|
api_str = "API OK"
|
||||||
items = [pystray.MenuItem("No units detected", None, enabled=False)]
|
elif api_status == "fail":
|
||||||
|
api_str = "API FAIL"
|
||||||
else:
|
else:
|
||||||
items = []
|
api_str = "API off"
|
||||||
for u in units:
|
|
||||||
label = "{uid} — {status} ({age:.1f}h ago)".format(
|
return "Running — {} | {} unit(s) | scan {}".format(api_str, unit_count, age_str)
|
||||||
uid=u["uid"],
|
|
||||||
status=u["status"],
|
def _tray_status(self):
|
||||||
age=u["age_hours"],
|
"""Return the icon status key based on watcher + API health."""
|
||||||
)
|
status = self.state.get("status", "starting")
|
||||||
items.append(pystray.MenuItem(label, None, enabled=False))
|
if status == "error":
|
||||||
return pystray.Menu(*items)
|
return "error"
|
||||||
|
if status == "starting":
|
||||||
|
return "starting"
|
||||||
|
api_status = self.state.get("api_status", "disabled")
|
||||||
|
if api_status == "fail":
|
||||||
|
return "missing" # red — API failing
|
||||||
|
if api_status == "disabled":
|
||||||
|
return "pending" # amber — running but not reporting
|
||||||
|
return "ok" # green — running and API good
|
||||||
|
|
||||||
def _build_menu(self):
|
def _build_menu(self):
|
||||||
# Capture current text/submenu at build time; pystray will call
|
|
||||||
# callables each render, but static strings are fine for infrequent
|
|
||||||
# menu rebuilds. We use callables for the dynamic items so that the
|
|
||||||
# text shown on hover/open is current.
|
|
||||||
status_text = self._status_text()
|
|
||||||
units_submenu = self._build_units_submenu()
|
|
||||||
|
|
||||||
return pystray.Menu(
|
return pystray.Menu(
|
||||||
pystray.MenuItem(status_text, None, enabled=False),
|
pystray.MenuItem(lambda item: self._status_text(), None, enabled=False),
|
||||||
pystray.Menu.SEPARATOR,
|
|
||||||
pystray.MenuItem("Units", units_submenu),
|
|
||||||
pystray.Menu.SEPARATOR,
|
pystray.Menu.SEPARATOR,
|
||||||
pystray.MenuItem("Settings...", self._open_settings),
|
pystray.MenuItem("Settings...", self._open_settings),
|
||||||
pystray.MenuItem("Open Log Folder", self._open_logs),
|
pystray.MenuItem("Open Log Folder", self._open_logs),
|
||||||
@@ -377,17 +334,17 @@ class WatcherTray:
|
|||||||
update_check_counter = 0 # check for updates every ~5 min (30 * 10s ticks)
|
update_check_counter = 0 # check for updates every ~5 min (30 * 10s ticks)
|
||||||
|
|
||||||
while not self.stop_event.is_set():
|
while not self.stop_event.is_set():
|
||||||
status = self.state.get("status", "starting")
|
icon_status = self._tray_status()
|
||||||
|
|
||||||
if self._icon is not None:
|
if self._icon is not None:
|
||||||
# Always rebuild menu every cycle so unit list and scan age stay fresh
|
# Always rebuild menu every cycle so status text stays fresh
|
||||||
with self._menu_lock:
|
with self._menu_lock:
|
||||||
self._icon.menu = self._build_menu()
|
self._icon.menu = self._build_menu()
|
||||||
|
|
||||||
if status != last_status:
|
if icon_status != last_status:
|
||||||
self._icon.icon = make_icon(status)
|
self._icon.icon = make_icon(icon_status)
|
||||||
self._icon.title = "Series 3 Watcher — {}".format(status.upper())
|
self._icon.title = "Series 3 Watcher — {}".format(self._status_text())
|
||||||
last_status = status
|
last_status = icon_status
|
||||||
|
|
||||||
# Check if terra-view signalled an update via heartbeat response
|
# Check if terra-view signalled an update via heartbeat response
|
||||||
if self.state.get("update_available"):
|
if self.state.get("update_available"):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Series 3 Watcher — v1.4.1
|
Series 3 Watcher — v1.4.2
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
- Python 3.8 (Windows 7 compatible)
|
- Python 3.8 (Windows 7 compatible)
|
||||||
@@ -68,7 +68,6 @@ def load_config(path: str) -> Dict[str, Any]:
|
|||||||
"Series3Watcher", "agent_logs", "series3_watcher.log"
|
"Series3Watcher", "agent_logs", "series3_watcher.log"
|
||||||
)),
|
)),
|
||||||
"LOG_RETENTION_DAYS": get_int("LOG_RETENTION_DAYS", 30),
|
"LOG_RETENTION_DAYS": get_int("LOG_RETENTION_DAYS", 30),
|
||||||
"COLORIZE": get_bool("COLORIZE", False), # Win7 default off
|
|
||||||
"MLG_HEADER_BYTES": max(256, min(get_int("MLG_HEADER_BYTES", 2048), 65536)),
|
"MLG_HEADER_BYTES": max(256, min(get_int("MLG_HEADER_BYTES", 2048), 65536)),
|
||||||
"RECENT_WARN_DAYS": get_int("RECENT_WARN_DAYS", 30),
|
"RECENT_WARN_DAYS": get_int("RECENT_WARN_DAYS", 30),
|
||||||
"MAX_EVENT_AGE_DAYS": get_int("MAX_EVENT_AGE_DAYS", 365),
|
"MAX_EVENT_AGE_DAYS": get_int("MAX_EVENT_AGE_DAYS", 365),
|
||||||
@@ -82,10 +81,6 @@ def load_config(path: str) -> Dict[str, Any]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# --------------- ANSI helpers ---------------
|
|
||||||
def ansi(enabled: bool, code: str) -> str:
|
|
||||||
return code if enabled else ""
|
|
||||||
|
|
||||||
|
|
||||||
# --------------- Logging --------------------
|
# --------------- Logging --------------------
|
||||||
def log_message(path: str, enabled: bool, msg: str) -> None:
|
def log_message(path: str, enabled: bool, msg: str) -> None:
|
||||||
@@ -220,7 +215,7 @@ def scan_latest(
|
|||||||
|
|
||||||
|
|
||||||
# --- API heartbeat / SFM telemetry helpers ---
|
# --- API heartbeat / SFM telemetry helpers ---
|
||||||
VERSION = "1.4.1"
|
VERSION = "1.4.2"
|
||||||
|
|
||||||
|
|
||||||
def _read_log_tail(log_file: str, n: int = 25) -> Optional[list]:
|
def _read_log_tail(log_file: str, n: int = 25) -> Optional[list]:
|
||||||
@@ -310,18 +305,23 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
|||||||
Main watcher loop. Runs in a background thread when launched from the tray.
|
Main watcher loop. Runs in a background thread when launched from the tray.
|
||||||
|
|
||||||
state dict is written on every scan cycle:
|
state dict is written on every scan cycle:
|
||||||
state["status"] — "ok" | "pending" | "missing" | "error" | "starting"
|
state["status"] — "running" | "error" | "starting"
|
||||||
state["units"] — list of dicts: {uid, status, age_hours, last, fname}
|
state["api_status"] — "ok" | "fail" | "disabled"
|
||||||
|
state["units"] — list of dicts: {uid, age_hours, last, fname}
|
||||||
state["last_scan"] — datetime of last successful scan (or None)
|
state["last_scan"] — datetime of last successful scan (or None)
|
||||||
|
state["last_api"] — datetime of last successful API POST (or None)
|
||||||
state["last_error"] — last error string (or None)
|
state["last_error"] — last error string (or None)
|
||||||
state["log_dir"] — directory containing the log file
|
state["log_dir"] — directory containing the log file
|
||||||
state["cfg"] — loaded config dict
|
state["cfg"] — loaded config dict
|
||||||
"""
|
"""
|
||||||
if getattr(sys, "frozen", False):
|
if getattr(sys, "frozen", False):
|
||||||
here = os.path.dirname(os.path.abspath(sys.executable))
|
here = os.path.dirname(os.path.abspath(sys.executable))
|
||||||
|
_appdata = os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or here
|
||||||
|
config_dir = os.path.join(_appdata, "Series3Watcher")
|
||||||
else:
|
else:
|
||||||
here = os.path.dirname(os.path.abspath(__file__)) or "."
|
here = os.path.dirname(os.path.abspath(__file__)) or "."
|
||||||
config_path = os.path.join(here, "config.ini")
|
config_dir = here
|
||||||
|
config_path = os.path.join(config_dir, "config.ini")
|
||||||
|
|
||||||
state["status"] = "starting"
|
state["status"] = "starting"
|
||||||
state["units"] = []
|
state["units"] = []
|
||||||
@@ -342,21 +342,13 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
|||||||
|
|
||||||
WATCH_PATH = cfg["WATCH_PATH"]
|
WATCH_PATH = cfg["WATCH_PATH"]
|
||||||
SCAN_INTERVAL = int(cfg["SCAN_INTERVAL"])
|
SCAN_INTERVAL = int(cfg["SCAN_INTERVAL"])
|
||||||
OK_HOURS = float(cfg["OK_HOURS"])
|
|
||||||
MISSING_HOURS = float(cfg["MISSING_HOURS"])
|
|
||||||
ENABLE_LOGGING = bool(cfg["ENABLE_LOGGING"])
|
ENABLE_LOGGING = bool(cfg["ENABLE_LOGGING"])
|
||||||
LOG_FILE = cfg["LOG_FILE"]
|
LOG_FILE = cfg["LOG_FILE"]
|
||||||
LOG_RETENTION_DAYS = int(cfg["LOG_RETENTION_DAYS"])
|
LOG_RETENTION_DAYS = int(cfg["LOG_RETENTION_DAYS"])
|
||||||
COLORIZE = bool(cfg["COLORIZE"])
|
|
||||||
MLG_HEADER_BYTES = int(cfg["MLG_HEADER_BYTES"])
|
MLG_HEADER_BYTES = int(cfg["MLG_HEADER_BYTES"])
|
||||||
RECENT_WARN_DAYS = int(cfg["RECENT_WARN_DAYS"])
|
RECENT_WARN_DAYS = int(cfg["RECENT_WARN_DAYS"])
|
||||||
MAX_EVENT_AGE_DAYS = int(cfg["MAX_EVENT_AGE_DAYS"])
|
MAX_EVENT_AGE_DAYS = int(cfg["MAX_EVENT_AGE_DAYS"])
|
||||||
|
|
||||||
C_OK = ansi(COLORIZE, "\033[92m")
|
|
||||||
C_PEN = ansi(COLORIZE, "\033[93m")
|
|
||||||
C_MIS = ansi(COLORIZE, "\033[91m")
|
|
||||||
C_RST = ansi(COLORIZE, "\033[0m")
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"[CFG] WATCH_PATH={} SCAN_INTERVAL={}s MAX_EVENT_AGE_DAYS={} API_ENABLED={}".format(
|
"[CFG] WATCH_PATH={} SCAN_INTERVAL={}s MAX_EVENT_AGE_DAYS={} API_ENABLED={}".format(
|
||||||
WATCH_PATH, SCAN_INTERVAL, MAX_EVENT_AGE_DAYS, bool(cfg.get("API_ENABLED", False))
|
WATCH_PATH, SCAN_INTERVAL, MAX_EVENT_AGE_DAYS, bool(cfg.get("API_ENABLED", False))
|
||||||
@@ -395,45 +387,25 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
|||||||
)
|
)
|
||||||
now_epoch = time.time()
|
now_epoch = time.time()
|
||||||
|
|
||||||
# Build per-unit status list for the tray
|
# Log detected units to console and log file (info only, no status judgement)
|
||||||
unit_list = []
|
unit_list = []
|
||||||
worst = "ok" # tracks worst status across all units
|
|
||||||
|
|
||||||
if latest:
|
if latest:
|
||||||
print("\nDetected Units (within last {} days):".format(MAX_EVENT_AGE_DAYS))
|
print("\nDetected Units (within last {} days):".format(MAX_EVENT_AGE_DAYS))
|
||||||
for uid in sorted(latest.keys()):
|
for uid in sorted(latest.keys()):
|
||||||
info = latest[uid]
|
info = latest[uid]
|
||||||
age_hours = (now_epoch - info["mtime"]) / 3600.0
|
age_hours = (now_epoch - info["mtime"]) / 3600.0
|
||||||
if age_hours > MISSING_HOURS:
|
|
||||||
status, col = "missing", C_MIS
|
|
||||||
elif age_hours > OK_HOURS:
|
|
||||||
status, col = "pending", C_PEN
|
|
||||||
else:
|
|
||||||
status, col = "ok", C_OK
|
|
||||||
|
|
||||||
# escalate worst status
|
|
||||||
if status == "missing":
|
|
||||||
worst = "missing"
|
|
||||||
elif status == "pending" and worst != "missing":
|
|
||||||
worst = "pending"
|
|
||||||
|
|
||||||
unit_list.append({
|
unit_list.append({
|
||||||
"uid": uid,
|
"uid": uid,
|
||||||
"status": status,
|
|
||||||
"age_hours": age_hours,
|
"age_hours": age_hours,
|
||||||
"last": fmt_last(info["mtime"]),
|
"last": fmt_last(info["mtime"]),
|
||||||
"fname": info["fname"],
|
"fname": info["fname"],
|
||||||
})
|
})
|
||||||
|
|
||||||
line = (
|
line = (
|
||||||
"{col}{uid:<8} {status:<8} Age: {age:<7} Last: {last} (File: {fname}){rst}".format(
|
"{uid:<8} Age: {age:<7} Last: {last} (File: {fname})".format(
|
||||||
col=col,
|
|
||||||
uid=uid,
|
uid=uid,
|
||||||
status=status.capitalize(),
|
|
||||||
age=fmt_age(now_epoch, info["mtime"]),
|
age=fmt_age(now_epoch, info["mtime"]),
|
||||||
last=fmt_last(info["mtime"]),
|
last=fmt_last(info["mtime"]),
|
||||||
fname=info["fname"],
|
fname=info["fname"],
|
||||||
rst=C_RST,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
print(line)
|
print(line)
|
||||||
@@ -445,10 +417,9 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
|||||||
ENABLE_LOGGING,
|
ENABLE_LOGGING,
|
||||||
"[info] no recent MLG activity within {} days".format(MAX_EVENT_AGE_DAYS),
|
"[info] no recent MLG activity within {} days".format(MAX_EVENT_AGE_DAYS),
|
||||||
)
|
)
|
||||||
worst = "missing"
|
|
||||||
|
|
||||||
# Update shared state for tray
|
# Update shared state for tray — status reflects watcher health, not unit ages
|
||||||
state["status"] = worst
|
state["status"] = "running"
|
||||||
state["units"] = unit_list
|
state["units"] = unit_list
|
||||||
state["last_scan"] = datetime.now()
|
state["last_scan"] = datetime.now()
|
||||||
state["last_error"] = None
|
state["last_error"] = None
|
||||||
@@ -460,12 +431,19 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> None:
|
|||||||
if now_ts - last_api_ts >= interval:
|
if now_ts - last_api_ts >= interval:
|
||||||
hb_payload = build_sfm_payload(latest, cfg)
|
hb_payload = build_sfm_payload(latest, cfg)
|
||||||
hb_payload["version"] = VERSION
|
hb_payload["version"] = VERSION
|
||||||
|
hb_payload["watcher_status"] = state.get("status", "unknown")
|
||||||
hb_payload["log_tail"] = _read_log_tail(cfg.get("LOG_FILE", ""), 25)
|
hb_payload["log_tail"] = _read_log_tail(cfg.get("LOG_FILE", ""), 25)
|
||||||
response = send_api_payload(hb_payload, cfg.get("API_URL", ""))
|
response = send_api_payload(hb_payload, cfg.get("API_URL", ""))
|
||||||
last_api_ts = now_ts
|
last_api_ts = now_ts
|
||||||
# Surface update signal to tray
|
if response is not None:
|
||||||
if response and response.get("update_available"):
|
state["api_status"] = "ok"
|
||||||
|
state["last_api"] = datetime.now()
|
||||||
|
if response.get("update_available"):
|
||||||
state["update_available"] = True
|
state["update_available"] = True
|
||||||
|
else:
|
||||||
|
state["api_status"] = "fail"
|
||||||
|
else:
|
||||||
|
state["api_status"] = "disabled"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err = "[loop-error] {}".format(e)
|
err = "[loop-error] {}".format(e)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Series 3 Watcher — Settings Dialog v1.4.0
|
Series 3 Watcher — Settings Dialog v1.4.2
|
||||||
|
|
||||||
Provides a Tkinter settings dialog that doubles as a first-run wizard.
|
Provides a Tkinter settings dialog that doubles as a first-run wizard.
|
||||||
|
|
||||||
@@ -39,7 +39,6 @@ DEFAULTS = {
|
|||||||
"Series3Watcher", "agent_logs", "series3_watcher.log"
|
"Series3Watcher", "agent_logs", "series3_watcher.log"
|
||||||
),
|
),
|
||||||
"LOG_RETENTION_DAYS": "30",
|
"LOG_RETENTION_DAYS": "30",
|
||||||
"COLORIZE": "false",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -233,7 +232,6 @@ class SettingsDialog:
|
|||||||
# Logging
|
# Logging
|
||||||
self.var_enable_logging = tk.BooleanVar(value=v["ENABLE_LOGGING"].lower() in ("1","true","yes","on"))
|
self.var_enable_logging = tk.BooleanVar(value=v["ENABLE_LOGGING"].lower() in ("1","true","yes","on"))
|
||||||
self.var_log_retention_days = tk.StringVar(value=v["LOG_RETENTION_DAYS"])
|
self.var_log_retention_days = tk.StringVar(value=v["LOG_RETENTION_DAYS"])
|
||||||
self.var_colorize = tk.BooleanVar(value=v["COLORIZE"].lower() in ("1","true","yes","on"))
|
|
||||||
|
|
||||||
# --- UI construction ---
|
# --- UI construction ---
|
||||||
|
|
||||||
@@ -399,7 +397,6 @@ class SettingsDialog:
|
|||||||
f = self._tab_frame(nb, "Logging")
|
f = self._tab_frame(nb, "Logging")
|
||||||
_add_label_check(f, 0, "Enable Logging", self.var_enable_logging)
|
_add_label_check(f, 0, "Enable Logging", self.var_enable_logging)
|
||||||
_add_label_spinbox(f, 1, "Log Retention (days)", self.var_log_retention_days, 1, 365)
|
_add_label_spinbox(f, 1, "Log Retention (days)", self.var_log_retention_days, 1, 365)
|
||||||
_add_label_check(f, 2, "Colorize console output", self.var_colorize)
|
|
||||||
|
|
||||||
# --- Validation helpers ---
|
# --- Validation helpers ---
|
||||||
|
|
||||||
@@ -470,7 +467,6 @@ class SettingsDialog:
|
|||||||
"ENABLE_LOGGING": "true" if self.var_enable_logging.get() else "false",
|
"ENABLE_LOGGING": "true" if self.var_enable_logging.get() else "false",
|
||||||
"LOG_FILE": self.var_log_file.get().strip(),
|
"LOG_FILE": self.var_log_file.get().strip(),
|
||||||
"LOG_RETENTION_DAYS": str(int_values["Log Retention Days"]),
|
"LOG_RETENTION_DAYS": str(int_values["Log Retention Days"]),
|
||||||
"COLORIZE": "true" if self.var_colorize.get() else "false",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user