Repository navigation
Automated beszel-agent deployment via TacticalRMM #1870
Replies: 2 comments 4 replies
|
Try using a regular user from I know it's a bit confusing, I'll see if I can update this to return an error if trying to create a universal token with a superuser account. |
|
I got it, thank you @henrygd! Additionally, i found that without a pre-defined identity, multiple agents could experience ID conflicts in the Hub, causing hostnames and uptimes to flicker on the dashboard (Race Condition). The Solution: What the script does: Identity Persistence (ID Fix): Since the SYSTEM account needs a defined path for configuration, the script generates a unique UUID via Python and injects it into an id.json file within the systemprofile directory. This ensures each agent registers as a unique entity in the Hub. Automated Installation: It downloads the latest binary directly from GitHub, extracts it in memory to avoid temporary file clutter, and sets up the service using NSSM with log redirection (stdout/stderr) enabled. Networking: It automatically creates the necessary Windows Firewall Inbound Rule for port 45876. Instead of clicking "Add System" for every single machine (which generates individual tokens), follow these steps to get the Universal Token: Login as a Standard User (not Global Admin) to ensure the systems appear in your specific dashboard. Access the User Settings: Click on your user icon/name in the bottom left or top right. Find "Universal Token": There is a section specifically for a Universal Token. This token allows multiple systems to register under the same user account using a single script. Public Key: The P_KEY (SSH key) is the same one used across your Hub instance for communication. Deployment Script: |
Uh oh!
There was an error while loading. Please reload this page.
I am a SysAdmin managing a fleet of 100+ Windows machines. My goal is to automate the deployment of the beszel-agent using TacticalRMM (Python scripts). I am using the Beszel Hub (PocketBase backend) to centralize monitoring.
Deployment Logic
My automation script performs the following steps:
Authenticates as a Superuser via API.
Retrieves the Universal Token and the Public Key from /api/beszel/universal-token and /api/beszel/getkey.
Cleans any previous agent identity at C:\Windows\System32\config\systemprofile\AppData\Roaming\beszel-agent.
Installs the agent as a Windows Service (using NSSM) passing the flags:
beszel-agent.exe -key "PUB_KEY" -token "UNIVERSAL_TOKEN" -url "HUB_URL".
The Issue
Even with a "clean slate" deployment, the agent consistently fails to connect, returning:
WARN WebSocket connection failed err="unexpected status code: 401"
Debugging Performed
I've conducted extensive API testing to isolate the cause:
API Inconsistency: Even when the Universal Token is enabled and set to "Permanent" in the Web UI, the API endpoint /api/beszel/universal-token often returns active: false.
Token Rejection: Manual HTTP requests simulating the agent handshake using the provided Universal Token return 401 Unauthorized, even when the token is copied directly from the Hub's own API response.
Identity Conflict: When attempting to create a system record via API (/api/collections/systems/records) to use an individual token, the Hub requires a relation to the users collection (plural), but the agent still fails to authenticate with the generated token if the UUIDs don't match some internal state.
Environment
Hub Version: 0.18.6 (as reported by /api/beszel/getkey)
Agent: Windows Binary (latest)
Backend: PocketBase
All reactions