Compare commits
10 Commits
1b8c63025f
...
v1.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 2456fd0ee8 | |||
|
|
d2fd3b7182 | ||
|
|
1d94c5dd04 | ||
|
|
814b6f915e | ||
|
|
9cfdebe553 | ||
|
|
f773e1dac9 | ||
|
|
326658ed26 | ||
|
|
504ee1d470 | ||
|
|
e67b6eb89f | ||
| c133932b29 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,7 +22,9 @@ env/
|
|||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
build/
|
build/
|
||||||
dist/
|
dist/
|
||||||
|
Output/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
|
*.spec
|
||||||
|
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Logs + runtime artifacts
|
# Logs + runtime artifacts
|
||||||
|
|||||||
117
BUILDING.md
Normal file
117
BUILDING.md
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
# Building & Releasing Series 3 Watcher
|
||||||
|
|
||||||
|
## Prerequisites (Win7 VM — do this once)
|
||||||
|
|
||||||
|
- Python 3.7.2 (or 3.8.10 if SP1 is installed)
|
||||||
|
- Inno Setup 6 — installed at `C:\Program Files (x86)\Inno Setup 6\`
|
||||||
|
- PyInstaller, pystray, Pillow — installed automatically by `build.bat`
|
||||||
|
|
||||||
|
The Win7 VM is the build machine. All builds must happen there to ensure
|
||||||
|
compatibility with the production DL2 computer.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## First-Time Install on a New Machine
|
||||||
|
|
||||||
|
Do this when setting up a brand new machine that has never had the watcher before.
|
||||||
|
|
||||||
|
**Step 1 — Build the .exe (on the Win7 VM)**
|
||||||
|
|
||||||
|
1. Copy the `series3-watcher/` folder to the VM (shared folder, USB, etc.)
|
||||||
|
2. Double-click `build.bat`
|
||||||
|
3. Wait for it to finish — output: `dist\series3-watcher.exe`
|
||||||
|
|
||||||
|
**Step 2 — Build the installer (on the Win7 VM)**
|
||||||
|
|
||||||
|
1. Open `installer.iss` in Inno Setup Compiler
|
||||||
|
2. Click **Build → Compile**
|
||||||
|
3. Output: `Output\series3-watcher-setup.exe`
|
||||||
|
|
||||||
|
**Step 3 — Create a Gitea release**
|
||||||
|
|
||||||
|
1. On your main machine, go to `https://gitea.serversdown.net/serversdown/series3-watcher`
|
||||||
|
2. Click **Releases → New Release**
|
||||||
|
3. Set the tag to match the version in `series3_watcher.py` (e.g. `v1.4.1`)
|
||||||
|
4. Upload **both** files as release assets:
|
||||||
|
- `dist\series3-watcher.exe` — used by the auto-updater on existing installs
|
||||||
|
- `Output\series3-watcher-setup.exe` — used for fresh installs
|
||||||
|
|
||||||
|
**Step 4 — Install on the target machine**
|
||||||
|
|
||||||
|
1. Download `series3-watcher-setup.exe` from the Gitea release
|
||||||
|
2. Run it on the target machine — installs to `C:\Program Files\Series3Watcher\`
|
||||||
|
3. The watcher launches automatically after install (or on next login)
|
||||||
|
4. The Setup Wizard appears on first run — fill in the Terra-View URL and Blastware path
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Releasing an Update (existing machines auto-update)
|
||||||
|
|
||||||
|
Do this for any code change — bug fix, new feature, etc.
|
||||||
|
|
||||||
|
**Step 1 — Bump the version**
|
||||||
|
|
||||||
|
In `series3_watcher.py`, update the `VERSION` string:
|
||||||
|
```python
|
||||||
|
VERSION = "1.4.2" # increment appropriately
|
||||||
|
```
|
||||||
|
Also update `installer.iss`:
|
||||||
|
```
|
||||||
|
AppVersion=1.4.2
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 2 — Build the .exe (on the Win7 VM)**
|
||||||
|
|
||||||
|
1. Pull the latest code to the VM
|
||||||
|
2. Double-click `build.bat`
|
||||||
|
3. Output: `dist\series3-watcher.exe`
|
||||||
|
|
||||||
|
> For hotfixes you can skip Inno Setup — existing machines only need the `.exe`.
|
||||||
|
> Only rebuild the installer if you need a fresh install package for a new machine.
|
||||||
|
|
||||||
|
**Step 3 — Create a Gitea release**
|
||||||
|
|
||||||
|
1. Go to `https://gitea.serversdown.net/serversdown/series3-watcher`
|
||||||
|
2. Click **Releases → New Release**
|
||||||
|
3. Tag must match the new version exactly (e.g. `v1.4.2`) — the auto-updater
|
||||||
|
compares this tag against its own version to decide whether to update
|
||||||
|
4. Upload `dist\series3-watcher.exe` as a release asset
|
||||||
|
5. Optionally upload `Output\series3-watcher-setup.exe` if you rebuilt the installer
|
||||||
|
|
||||||
|
**Step 4 — Done**
|
||||||
|
|
||||||
|
Existing installs check Gitea every ~5 minutes. When they see the new tag they
|
||||||
|
will download `series3-watcher.exe`, swap it in place, and relaunch silently.
|
||||||
|
No user action required on the target machine.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Version Numbering
|
||||||
|
|
||||||
|
Follows Semantic Versioning: `MAJOR.MINOR.PATCH`
|
||||||
|
|
||||||
|
| Change type | Example |
|
||||||
|
|-------------|---------|
|
||||||
|
| Bug fix / text change | `1.4.1 → 1.4.2` |
|
||||||
|
| New feature | `1.4.x → 1.5.0` |
|
||||||
|
| Breaking change | `1.x.x → 2.0.0` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Files That Go in the Gitea Release
|
||||||
|
|
||||||
|
| File | Required for | Notes |
|
||||||
|
|------|-------------|-------|
|
||||||
|
| `dist\series3-watcher.exe` | Auto-updates on existing machines | Always upload this |
|
||||||
|
| `Output\series3-watcher-setup.exe` | Fresh installs on new machines | Only needed for new deployments |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Files That Are NOT Committed to Git
|
||||||
|
|
||||||
|
- `dist/` — PyInstaller output
|
||||||
|
- `Output/` — Inno Setup output
|
||||||
|
- `build/` — PyInstaller temp files
|
||||||
|
- `*.spec` — PyInstaller spec file
|
||||||
|
- `config.ini` — machine-specific, never commit
|
||||||
|
- `agent_logs/` — log files
|
||||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [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
|
||||||
|
|||||||
25
README.md
25
README.md
@@ -1,4 +1,4 @@
|
|||||||
# Series 3 Watcher v1.4
|
# Series 3 Watcher v1.4.1
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
@@ -23,21 +23,12 @@ Updates can also be pushed remotely from terra-view → **Settings → Developer
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Building from Source
|
## Building & Releasing
|
||||||
|
|
||||||
Prerequisites (on a **Python 3.8** machine — required for Win7 compatibility):
|
See [BUILDING.md](BUILDING.md) for the full step-by-step process covering:
|
||||||
|
- First-time build and installer creation
|
||||||
```
|
- Publishing a release to Gitea
|
||||||
pip install pystray Pillow pyinstaller
|
- Releasing hotfix updates (auto-updater picks them up automatically)
|
||||||
```
|
|
||||||
|
|
||||||
Then run:
|
|
||||||
|
|
||||||
```
|
|
||||||
build.bat
|
|
||||||
```
|
|
||||||
|
|
||||||
This produces `dist\series3-watcher.exe`. To build the installer, open `installer.iss` in [Inno Setup](https://jrsoftware.org/isinfo.php) and click Build.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -62,7 +53,7 @@ All settings live in `config.ini`. The Setup Wizard covers every field, but here
|
|||||||
| Key | Description |
|
| Key | Description |
|
||||||
|-----|-------------|
|
|-----|-------------|
|
||||||
| `API_ENABLED` | `true` to send heartbeats to terra-view |
|
| `API_ENABLED` | `true` to send heartbeats to terra-view |
|
||||||
| `API_URL` | terra-view heartbeat endpoint, e.g. `http://192.168.1.10:8000/api/series3/heartbeat` |
|
| `API_URL` | Terra-View base URL, e.g. `http://192.168.1.10:8000` — the `/api/series3/heartbeat` endpoint is appended automatically |
|
||||||
| `API_INTERVAL_SECONDS` | How often to POST (default `300`) |
|
| `API_INTERVAL_SECONDS` | How often to POST (default `300`) |
|
||||||
| `SOURCE_ID` | Identifier for this machine (defaults to hostname) |
|
| `SOURCE_ID` | Identifier for this machine (defaults to hostname) |
|
||||||
| `SOURCE_TYPE` | Always `series3_watcher` |
|
| `SOURCE_TYPE` | Always `series3_watcher` |
|
||||||
@@ -126,7 +117,7 @@ To view connected watchers: **Settings → Developer → Watcher Manager**.
|
|||||||
|
|
||||||
## Versioning
|
## Versioning
|
||||||
|
|
||||||
Follows **Semantic Versioning**. Current release: **v1.4.0**.
|
Follows **Semantic Versioning**. Current release: **v1.4.1**.
|
||||||
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
|
|
||||||
@@ -3,9 +3,13 @@ echo Building series3-watcher.exe...
|
|||||||
pip install pyinstaller pystray Pillow
|
pip install pyinstaller pystray Pillow
|
||||||
|
|
||||||
REM Check whether icon.ico exists alongside this script.
|
REM Check whether icon.ico exists alongside this script.
|
||||||
REM If it does, include it; otherwise build without a custom icon.
|
REM If it does, embed it as the .exe icon AND bundle it as a data file
|
||||||
|
REM so the tray overlay can load it at runtime.
|
||||||
if exist "%~dp0icon.ico" (
|
if exist "%~dp0icon.ico" (
|
||||||
pyinstaller --onefile --windowed --name series3-watcher --icon="%~dp0icon.ico" series3_tray.py
|
pyinstaller --onefile --windowed --name series3-watcher ^
|
||||||
|
--icon="%~dp0icon.ico" ^
|
||||||
|
--add-data "%~dp0icon.ico;." ^
|
||||||
|
series3_tray.py
|
||||||
) else (
|
) else (
|
||||||
echo [INFO] icon.ico not found -- building without custom icon.
|
echo [INFO] icon.ico not found -- building without custom icon.
|
||||||
pyinstaller --onefile --windowed --name series3-watcher series3_tray.py
|
pyinstaller --onefile --windowed --name series3-watcher series3_tray.py
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ MISSING_HOURS = 24
|
|||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
ENABLE_LOGGING = True
|
ENABLE_LOGGING = True
|
||||||
LOG_FILE = C:\SeismoEmitter\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)
|
# Console colors - (Doesn't work on windows 7)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[Setup]
|
[Setup]
|
||||||
AppName=Series 3 Watcher
|
AppName=Series 3 Watcher
|
||||||
AppVersion=1.4.0
|
AppVersion=1.4.1
|
||||||
AppPublisher=Terra-Mechanics Inc.
|
AppPublisher=Terra-Mechanics Inc.
|
||||||
DefaultDirName={pf}\Series3Watcher
|
DefaultDirName={pf}\Series3Watcher
|
||||||
DefaultGroupName=Series 3 Watcher
|
DefaultGroupName=Series 3 Watcher
|
||||||
@@ -16,6 +16,10 @@ PrivilegesRequired=admin
|
|||||||
[Tasks]
|
[Tasks]
|
||||||
Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: unchecked
|
Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: unchecked
|
||||||
|
|
||||||
|
[Dirs]
|
||||||
|
; Create the agent_logs folder so the watcher can write logs on first run
|
||||||
|
Name: "{app}\agent_logs"
|
||||||
|
|
||||||
[Files]
|
[Files]
|
||||||
; Main executable — built by build.bat / PyInstaller
|
; Main executable — built by build.bat / PyInstaller
|
||||||
Source: "dist\series3-watcher.exe"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "dist\series3-watcher.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Series 3 Watcher — System Tray Launcher v1.4.0
|
Series 3 Watcher — System Tray Launcher v1.4.1
|
||||||
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)
|
||||||
@@ -126,8 +126,21 @@ def apply_update(download_url):
|
|||||||
|
|
||||||
# --------------- Paths ---------------
|
# --------------- Paths ---------------
|
||||||
|
|
||||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
# Executable location — used for bundled assets (icon.ico etc.)
|
||||||
CONFIG_PATH = os.path.join(HERE, "config.ini")
|
if getattr(sys, "frozen", False):
|
||||||
|
HERE = os.path.dirname(os.path.abspath(sys.executable))
|
||||||
|
else:
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
# config.ini lives in AppData so normal users can write it without UAC issues.
|
||||||
|
# Fall back to the exe directory when running from source (dev mode).
|
||||||
|
if getattr(sys, "frozen", False):
|
||||||
|
_appdata = os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or HERE
|
||||||
|
CONFIG_DIR = os.path.join(_appdata, "Series3Watcher")
|
||||||
|
os.makedirs(CONFIG_DIR, exist_ok=True)
|
||||||
|
else:
|
||||||
|
CONFIG_DIR = HERE
|
||||||
|
CONFIG_PATH = os.path.join(CONFIG_DIR, "config.ini")
|
||||||
|
|
||||||
|
|
||||||
# --------------- Icon drawing ---------------
|
# --------------- Icon drawing ---------------
|
||||||
@@ -144,7 +157,7 @@ ICON_SIZE = 64
|
|||||||
|
|
||||||
|
|
||||||
def make_icon(status):
|
def make_icon(status):
|
||||||
"""Draw a solid filled circle on a transparent background."""
|
"""Draw a plain colored circle for the system tray — clean and readable at 16px."""
|
||||||
color = COLORS.get(status, COLORS["starting"])
|
color = COLORS.get(status, COLORS["starting"])
|
||||||
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)
|
||||||
@@ -233,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."""
|
||||||
from settings_dialog import show_dialog
|
def _run():
|
||||||
saved = show_dialog(CONFIG_PATH, wizard=False)
|
from settings_dialog import show_dialog
|
||||||
if saved:
|
saved = show_dialog(CONFIG_PATH, wizard=False)
|
||||||
self._restart_watcher()
|
if saved:
|
||||||
# Rebuild menu so status label refreshes
|
self._restart_watcher()
|
||||||
if self._icon is not None:
|
threading.Thread(target=_run, daemon=True, name="settings-dialog").start()
|
||||||
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")
|
||||||
@@ -299,17 +310,12 @@ class WatcherTray:
|
|||||||
return pystray.Menu(*items)
|
return pystray.Menu(*items)
|
||||||
|
|
||||||
def _build_menu(self):
|
def _build_menu(self):
|
||||||
# Capture current text/submenu at build time; pystray will call
|
# Use a callable for the status item so pystray re-evaluates it
|
||||||
# callables each render, but static strings are fine for infrequent
|
# every time the menu is opened — keeps it in sync with the tooltip.
|
||||||
# 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.Menu.SEPARATOR,
|
||||||
pystray.MenuItem("Units", units_submenu),
|
pystray.MenuItem("Units", lambda item: self._build_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),
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Series 3 Watcher — v1.4.0
|
Series 3 Watcher — v1.4.1
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
- Python 3.8 (Windows 7 compatible)
|
- Python 3.8 (Windows 7 compatible)
|
||||||
@@ -17,6 +17,7 @@ Key Features:
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
@@ -62,7 +63,10 @@ def load_config(path: str) -> Dict[str, Any]:
|
|||||||
"OK_HOURS": float(get_int("OK_HOURS", 12)),
|
"OK_HOURS": float(get_int("OK_HOURS", 12)),
|
||||||
"MISSING_HOURS": float(get_int("MISSING_HOURS", 24)),
|
"MISSING_HOURS": float(get_int("MISSING_HOURS", 24)),
|
||||||
"ENABLE_LOGGING": get_bool("ENABLE_LOGGING", True),
|
"ENABLE_LOGGING": get_bool("ENABLE_LOGGING", True),
|
||||||
"LOG_FILE": get_str("LOG_FILE", r"C:\SeismoEmitter\agent_logs\series3_watcher.log"),
|
"LOG_FILE": get_str("LOG_FILE", os.path.join(
|
||||||
|
os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or "C:\\",
|
||||||
|
"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
|
"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)),
|
||||||
@@ -216,7 +220,19 @@ def scan_latest(
|
|||||||
|
|
||||||
|
|
||||||
# --- API heartbeat / SFM telemetry helpers ---
|
# --- API heartbeat / SFM telemetry helpers ---
|
||||||
VERSION = "1.4.0"
|
VERSION = "1.4.1"
|
||||||
|
|
||||||
|
|
||||||
|
def _read_log_tail(log_file: str, n: int = 25) -> Optional[list]:
|
||||||
|
"""Return the last n lines of the log file as a list of strings, or None on failure."""
|
||||||
|
if not log_file:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
with open(log_file, "r", errors="replace") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
return [l.rstrip("\n") for l in lines[-n:]]
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def send_api_payload(payload: dict, api_url: str) -> Optional[dict]:
|
def send_api_payload(payload: dict, api_url: str) -> Optional[dict]:
|
||||||
@@ -301,8 +317,14 @@ def run_watcher(state: Dict[str, Any], stop_event: threading.Event) -> 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
|
||||||
"""
|
"""
|
||||||
here = os.path.dirname(__file__) or "."
|
if getattr(sys, "frozen", False):
|
||||||
config_path = os.path.join(here, "config.ini")
|
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:
|
||||||
|
here = os.path.dirname(os.path.abspath(__file__)) or "."
|
||||||
|
config_dir = here
|
||||||
|
config_path = os.path.join(config_dir, "config.ini")
|
||||||
|
|
||||||
state["status"] = "starting"
|
state["status"] = "starting"
|
||||||
state["units"] = []
|
state["units"] = []
|
||||||
@@ -441,6 +463,7 @@ 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["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
|
# Surface update signal to tray
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ DEFAULTS = {
|
|||||||
"MISSING_HOURS": "24",
|
"MISSING_HOURS": "24",
|
||||||
"MLG_HEADER_BYTES": "2048",
|
"MLG_HEADER_BYTES": "2048",
|
||||||
"ENABLE_LOGGING": "true",
|
"ENABLE_LOGGING": "true",
|
||||||
"LOG_FILE": r"C:\SeismoEmitter\agent_logs\series3_watcher.log",
|
"LOG_FILE": os.path.join(
|
||||||
|
os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or "C:\\",
|
||||||
|
"Series3Watcher", "agent_logs", "series3_watcher.log"
|
||||||
|
),
|
||||||
"LOG_RETENTION_DAYS": "30",
|
"LOG_RETENTION_DAYS": "30",
|
||||||
"COLORIZE": "false",
|
"COLORIZE": "false",
|
||||||
}
|
}
|
||||||
@@ -206,7 +209,12 @@ class SettingsDialog:
|
|||||||
|
|
||||||
# Connection
|
# Connection
|
||||||
self.var_api_enabled = tk.BooleanVar(value=v["API_ENABLED"].lower() in ("1","true","yes","on"))
|
self.var_api_enabled = tk.BooleanVar(value=v["API_ENABLED"].lower() in ("1","true","yes","on"))
|
||||||
self.var_api_url = tk.StringVar(value=v["API_URL"])
|
# Strip the fixed endpoint suffix so the dialog shows just the base URL
|
||||||
|
_raw_url = v["API_URL"]
|
||||||
|
_suffix = "/api/series3/heartbeat"
|
||||||
|
if _raw_url.endswith(_suffix):
|
||||||
|
_raw_url = _raw_url[:-len(_suffix)]
|
||||||
|
self.var_api_url = tk.StringVar(value=_raw_url)
|
||||||
self.var_api_interval = tk.StringVar(value=v["API_INTERVAL_SECONDS"])
|
self.var_api_interval = tk.StringVar(value=v["API_INTERVAL_SECONDS"])
|
||||||
self.var_source_id = tk.StringVar(value=v["SOURCE_ID"])
|
self.var_source_id = tk.StringVar(value=v["SOURCE_ID"])
|
||||||
self.var_source_type = tk.StringVar(value=v["SOURCE_TYPE"])
|
self.var_source_type = tk.StringVar(value=v["SOURCE_TYPE"])
|
||||||
@@ -277,10 +285,40 @@ class SettingsDialog:
|
|||||||
|
|
||||||
_add_label_check(f, 0, "API Enabled", self.var_api_enabled)
|
_add_label_check(f, 0, "API Enabled", self.var_api_enabled)
|
||||||
|
|
||||||
_add_label_entry(
|
# URL row — entry + Test button in an inner frame
|
||||||
f, 1, "terra-view URL", self.var_api_url,
|
tk.Label(f, text="Terra-View URL", anchor="w").grid(
|
||||||
hint="http://192.168.x.x:8000/api/heartbeat",
|
row=1, column=0, sticky="w", padx=(8, 4), pady=4
|
||||||
)
|
)
|
||||||
|
url_frame = tk.Frame(f)
|
||||||
|
url_frame.grid(row=1, column=1, sticky="ew", padx=(0, 8), pady=4)
|
||||||
|
url_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
url_entry = ttk.Entry(url_frame, textvariable=self.var_api_url, width=32)
|
||||||
|
url_entry.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
|
# Placeholder hint behaviour
|
||||||
|
_hint = "http://192.168.x.x:8000"
|
||||||
|
if not self.var_api_url.get():
|
||||||
|
url_entry.config(foreground="grey")
|
||||||
|
url_entry.insert(0, _hint)
|
||||||
|
def _on_focus_in(e):
|
||||||
|
if url_entry.get() == _hint:
|
||||||
|
url_entry.delete(0, tk.END)
|
||||||
|
url_entry.config(foreground="black")
|
||||||
|
def _on_focus_out(e):
|
||||||
|
if not url_entry.get():
|
||||||
|
url_entry.config(foreground="grey")
|
||||||
|
url_entry.insert(0, _hint)
|
||||||
|
self.var_api_url.set("")
|
||||||
|
url_entry.bind("<FocusIn>", _on_focus_in)
|
||||||
|
url_entry.bind("<FocusOut>", _on_focus_out)
|
||||||
|
|
||||||
|
self._test_btn = ttk.Button(url_frame, text="Test", width=6,
|
||||||
|
command=self._test_connection)
|
||||||
|
self._test_btn.grid(row=0, column=1, padx=(4, 0))
|
||||||
|
|
||||||
|
self._test_status = tk.Label(url_frame, text="", anchor="w", width=20)
|
||||||
|
self._test_status.grid(row=0, column=2, padx=(6, 0))
|
||||||
|
|
||||||
_add_label_spinbox(f, 2, "API Interval (sec)", self.var_api_interval, 30, 3600)
|
_add_label_spinbox(f, 2, "API Interval (sec)", self.var_api_interval, 30, 3600)
|
||||||
|
|
||||||
@@ -289,6 +327,40 @@ class SettingsDialog:
|
|||||||
|
|
||||||
_add_label_entry(f, 4, "Source Type", self.var_source_type, readonly=True)
|
_add_label_entry(f, 4, "Source Type", self.var_source_type, readonly=True)
|
||||||
|
|
||||||
|
def _test_connection(self):
|
||||||
|
"""POST a minimal ping to the Terra-View heartbeat endpoint and show result."""
|
||||||
|
import urllib.request
|
||||||
|
import urllib.error
|
||||||
|
|
||||||
|
self._test_status.config(text="Testing...", foreground="grey")
|
||||||
|
self._test_btn.config(state="disabled")
|
||||||
|
self.root.update_idletasks()
|
||||||
|
|
||||||
|
raw = self.var_api_url.get().strip()
|
||||||
|
if not raw or raw == "http://192.168.x.x:8000":
|
||||||
|
self._test_status.config(text="Enter a URL first", foreground="orange")
|
||||||
|
self._test_btn.config(state="normal")
|
||||||
|
return
|
||||||
|
|
||||||
|
url = raw.rstrip("/") + "/health"
|
||||||
|
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(url)
|
||||||
|
with urllib.request.urlopen(req, timeout=5) as resp:
|
||||||
|
if resp.status == 200:
|
||||||
|
self._test_status.config(text="Connected!", foreground="green")
|
||||||
|
else:
|
||||||
|
self._test_status.config(
|
||||||
|
text="HTTP {}".format(resp.status), foreground="orange"
|
||||||
|
)
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
reason = str(e.reason) if hasattr(e, "reason") else str(e)
|
||||||
|
self._test_status.config(text="Failed: {}".format(reason[:30]), foreground="red")
|
||||||
|
except Exception as e:
|
||||||
|
self._test_status.config(text="Error: {}".format(str(e)[:30]), foreground="red")
|
||||||
|
finally:
|
||||||
|
self._test_btn.config(state="normal")
|
||||||
|
|
||||||
def _build_tab_paths(self, nb):
|
def _build_tab_paths(self, nb):
|
||||||
f = self._tab_frame(nb, "Paths")
|
f = self._tab_frame(nb, "Paths")
|
||||||
|
|
||||||
@@ -376,13 +448,12 @@ class SettingsDialog:
|
|||||||
if source_id.startswith("Defaults to hostname"):
|
if source_id.startswith("Defaults to hostname"):
|
||||||
source_id = ""
|
source_id = ""
|
||||||
|
|
||||||
# Resolve api_url placeholder
|
# Resolve api_url — append the fixed endpoint, strip placeholder
|
||||||
api_url = self.var_api_url.get().strip()
|
api_url = self.var_api_url.get().strip()
|
||||||
if api_url.startswith("http://192.168"):
|
if api_url == "http://192.168.x.x:8000" or not api_url:
|
||||||
# This is the hint — only keep it if it looks like a real URL
|
|
||||||
pass # leave as-is; user may have typed it intentionally
|
|
||||||
if api_url == "http://192.168.x.x:8000/api/heartbeat":
|
|
||||||
api_url = ""
|
api_url = ""
|
||||||
|
else:
|
||||||
|
api_url = api_url.rstrip("/") + "/api/series3/heartbeat"
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
"API_ENABLED": "true" if self.var_api_enabled.get() else "false",
|
"API_ENABLED": "true" if self.var_api_enabled.get() else "false",
|
||||||
|
|||||||
Reference in New Issue
Block a user