Add VPN configuration tools and agent documentation
Created comprehensive VPN setup tooling for Peaceful Spirit L2TP/IPsec connection and enhanced agent documentation framework. VPN Configuration (PST-NW-VPN): - Setup-PST-L2TP-VPN.ps1: Automated L2TP/IPsec setup with split-tunnel and DNS - Connect-PST-VPN.ps1: Connection helper with PPP adapter detection, DNS (192.168.0.2), and route config (192.168.0.0/24) - Connect-PST-VPN-Standalone.ps1: Self-contained connection script for remote deployment - Fix-PST-VPN-Auth.ps1: Authentication troubleshooting for CHAP/MSChapv2 - Diagnose-VPN-Interface.ps1: Comprehensive VPN interface and routing diagnostic - Quick-Test-VPN.ps1: Fast connectivity verification (DNS/router/routes) - Add-PST-VPN-Route-Manual.ps1: Manual route configuration helper - vpn-connect.bat, vpn-disconnect.bat: Simple batch file shortcuts - OpenVPN config files (Windows-compatible, abandoned for L2TP) Key VPN Implementation Details: - L2TP creates PPP adapter with connection name as interface description - UniFi auto-configures DNS (192.168.0.2) but requires manual route to 192.168.0.0/24 - Split-tunnel enabled (only remote traffic through VPN) - All-user connection for pre-login auto-connect via scheduled task - Authentication: CHAP + MSChapv2 for UniFi compatibility Agent Documentation: - AGENT_QUICK_REFERENCE.md: Quick reference for all specialized agents - documentation-squire.md: Documentation and task management specialist agent - Updated all agent markdown files with standardized formatting Project Organization: - Moved conversation logs to dedicated directories (guru-connect-conversation-logs, guru-rmm-conversation-logs) - Cleaned up old session JSONL files from projects/msp-tools/ - Added guru-connect infrastructure (agent, dashboard, proto, scripts, .gitea workflows) - Added guru-rmm server components and deployment configs Technical Notes: - VPN IP pool: 192.168.4.x (client gets 192.168.4.6) - Remote network: 192.168.0.0/24 (router at 192.168.0.10) - PSK: rrClvnmUeXEFo90Ol+z7tfsAZHeSK6w7 - Credentials: pst-admin / 24Hearts$ Files: 15 VPN scripts, 2 agent docs, conversation log reorganization, guru-connect/guru-rmm infrastructure additions Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
122
projects/msp-tools/guru-rmm/server/migrations/001_initial.sql
Normal file
122
projects/msp-tools/guru-rmm/server/migrations/001_initial.sql
Normal file
@@ -0,0 +1,122 @@
|
||||
-- GuruRMM Initial Schema
|
||||
-- Creates tables for agents, metrics, commands, watchdog events, and users
|
||||
|
||||
-- Enable UUID extension
|
||||
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||
|
||||
-- Agents table
|
||||
-- Stores registered agents and their current status
|
||||
CREATE TABLE agents (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hostname VARCHAR(255) NOT NULL,
|
||||
api_key_hash VARCHAR(255) NOT NULL,
|
||||
os_type VARCHAR(50) NOT NULL,
|
||||
os_version VARCHAR(100),
|
||||
agent_version VARCHAR(50),
|
||||
last_seen TIMESTAMPTZ,
|
||||
status VARCHAR(20) DEFAULT 'offline',
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Index for looking up agents by hostname
|
||||
CREATE INDEX idx_agents_hostname ON agents(hostname);
|
||||
|
||||
-- Index for finding online agents
|
||||
CREATE INDEX idx_agents_status ON agents(status);
|
||||
|
||||
-- Metrics table
|
||||
-- Time-series data for system metrics from agents
|
||||
CREATE TABLE metrics (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
agent_id UUID NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
timestamp TIMESTAMPTZ DEFAULT NOW(),
|
||||
cpu_percent REAL,
|
||||
memory_percent REAL,
|
||||
memory_used_bytes BIGINT,
|
||||
disk_percent REAL,
|
||||
disk_used_bytes BIGINT,
|
||||
network_rx_bytes BIGINT,
|
||||
network_tx_bytes BIGINT
|
||||
);
|
||||
|
||||
-- Index for querying metrics by agent and time
|
||||
CREATE INDEX idx_metrics_agent_time ON metrics(agent_id, timestamp DESC);
|
||||
|
||||
-- Index for finding recent metrics
|
||||
CREATE INDEX idx_metrics_timestamp ON metrics(timestamp DESC);
|
||||
|
||||
-- Users table
|
||||
-- Dashboard users for authentication
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255),
|
||||
name VARCHAR(255),
|
||||
role VARCHAR(50) DEFAULT 'user',
|
||||
sso_provider VARCHAR(50),
|
||||
sso_id VARCHAR(255),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
last_login TIMESTAMPTZ
|
||||
);
|
||||
|
||||
-- Index for email lookups during login
|
||||
CREATE INDEX idx_users_email ON users(email);
|
||||
|
||||
-- Index for SSO lookups
|
||||
CREATE INDEX idx_users_sso ON users(sso_provider, sso_id);
|
||||
|
||||
-- Commands table
|
||||
-- Commands sent to agents and their results
|
||||
CREATE TABLE commands (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
agent_id UUID NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
command_type VARCHAR(50) NOT NULL,
|
||||
command_text TEXT NOT NULL,
|
||||
status VARCHAR(20) DEFAULT 'pending',
|
||||
exit_code INTEGER,
|
||||
stdout TEXT,
|
||||
stderr TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
started_at TIMESTAMPTZ,
|
||||
completed_at TIMESTAMPTZ,
|
||||
created_by UUID REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
-- Index for finding pending commands for an agent
|
||||
CREATE INDEX idx_commands_agent_status ON commands(agent_id, status);
|
||||
|
||||
-- Index for command history queries
|
||||
CREATE INDEX idx_commands_created ON commands(created_at DESC);
|
||||
|
||||
-- Watchdog events table
|
||||
-- Events from agent watchdog monitoring
|
||||
CREATE TABLE watchdog_events (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
agent_id UUID NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
timestamp TIMESTAMPTZ DEFAULT NOW(),
|
||||
service_name VARCHAR(255) NOT NULL,
|
||||
event_type VARCHAR(50) NOT NULL,
|
||||
details TEXT
|
||||
);
|
||||
|
||||
-- Index for querying events by agent and time
|
||||
CREATE INDEX idx_watchdog_agent_time ON watchdog_events(agent_id, timestamp DESC);
|
||||
|
||||
-- Index for finding recent events
|
||||
CREATE INDEX idx_watchdog_timestamp ON watchdog_events(timestamp DESC);
|
||||
|
||||
-- Function to update updated_at timestamp
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = NOW();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Trigger for agents table
|
||||
CREATE TRIGGER update_agents_updated_at
|
||||
BEFORE UPDATE ON agents
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
@@ -0,0 +1,100 @@
|
||||
-- GuruRMM Clients and Sites Schema
|
||||
-- Adds multi-tenant support with clients, sites, and site-based agent registration
|
||||
|
||||
-- Clients table (organizations/companies)
|
||||
CREATE TABLE clients (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
code VARCHAR(50) UNIQUE, -- Optional short code like "ACME"
|
||||
notes TEXT,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_clients_name ON clients(name);
|
||||
CREATE INDEX idx_clients_code ON clients(code);
|
||||
|
||||
-- Trigger for clients updated_at
|
||||
CREATE TRIGGER update_clients_updated_at
|
||||
BEFORE UPDATE ON clients
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
-- Sites table (locations under a client)
|
||||
CREATE TABLE sites (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
client_id UUID NOT NULL REFERENCES clients(id) ON DELETE CASCADE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
-- Site code: human-friendly, used for agent registration (e.g., "BLUE-TIGER-4829")
|
||||
site_code VARCHAR(50) UNIQUE NOT NULL,
|
||||
-- API key hash for this site (all agents at site share this key)
|
||||
api_key_hash VARCHAR(255) NOT NULL,
|
||||
address TEXT,
|
||||
notes TEXT,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_sites_client ON sites(client_id);
|
||||
CREATE INDEX idx_sites_code ON sites(site_code);
|
||||
CREATE INDEX idx_sites_api_key ON sites(api_key_hash);
|
||||
|
||||
-- Trigger for sites updated_at
|
||||
CREATE TRIGGER update_sites_updated_at
|
||||
BEFORE UPDATE ON sites
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
-- Add new columns to agents table
|
||||
-- device_id: unique hardware-derived identifier for the machine
|
||||
ALTER TABLE agents ADD COLUMN device_id VARCHAR(255);
|
||||
|
||||
-- site_id: which site this agent belongs to (nullable for legacy agents)
|
||||
ALTER TABLE agents ADD COLUMN site_id UUID REFERENCES sites(id) ON DELETE SET NULL;
|
||||
|
||||
-- Make api_key_hash nullable (new agents will use site's api_key)
|
||||
ALTER TABLE agents ALTER COLUMN api_key_hash DROP NOT NULL;
|
||||
|
||||
-- Index for looking up agents by device_id within a site
|
||||
CREATE UNIQUE INDEX idx_agents_site_device ON agents(site_id, device_id) WHERE site_id IS NOT NULL AND device_id IS NOT NULL;
|
||||
|
||||
-- Index for site lookups
|
||||
CREATE INDEX idx_agents_site ON agents(site_id);
|
||||
|
||||
-- Registration tokens table (optional: for secure site code distribution)
|
||||
CREATE TABLE registration_tokens (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
site_id UUID NOT NULL REFERENCES sites(id) ON DELETE CASCADE,
|
||||
token_hash VARCHAR(255) NOT NULL,
|
||||
description VARCHAR(255),
|
||||
uses_remaining INTEGER, -- NULL = unlimited
|
||||
expires_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
created_by UUID REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_reg_tokens_site ON registration_tokens(site_id);
|
||||
CREATE INDEX idx_reg_tokens_hash ON registration_tokens(token_hash);
|
||||
|
||||
-- Function to generate a random site code (WORD-WORD-####)
|
||||
-- This is just a helper; actual generation should be in application code
|
||||
-- for better word lists
|
||||
CREATE OR REPLACE FUNCTION generate_site_code() RETURNS VARCHAR(50) AS $$
|
||||
DECLARE
|
||||
words TEXT[] := ARRAY['ALPHA', 'BETA', 'GAMMA', 'DELTA', 'ECHO', 'FOXTROT',
|
||||
'BLUE', 'GREEN', 'RED', 'GOLD', 'SILVER', 'IRON',
|
||||
'HAWK', 'EAGLE', 'TIGER', 'LION', 'WOLF', 'BEAR',
|
||||
'NORTH', 'SOUTH', 'EAST', 'WEST', 'PEAK', 'VALLEY',
|
||||
'RIVER', 'OCEAN', 'STORM', 'CLOUD', 'STAR', 'MOON'];
|
||||
word1 TEXT;
|
||||
word2 TEXT;
|
||||
num INTEGER;
|
||||
BEGIN
|
||||
word1 := words[1 + floor(random() * array_length(words, 1))::int];
|
||||
word2 := words[1 + floor(random() * array_length(words, 1))::int];
|
||||
num := 1000 + floor(random() * 9000)::int;
|
||||
RETURN word1 || '-' || word2 || '-' || num::text;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
@@ -0,0 +1,34 @@
|
||||
-- Extended metrics and agent state
|
||||
-- Adds columns for uptime, user info, IPs, and network state storage
|
||||
|
||||
-- Add extended columns to metrics table
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS uptime_seconds BIGINT;
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS boot_time BIGINT;
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS logged_in_user VARCHAR(255);
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS user_idle_seconds BIGINT;
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS public_ip VARCHAR(45); -- Supports IPv6
|
||||
|
||||
-- Agent state table for current/latest agent information
|
||||
-- This stores the latest snapshot of extended agent info (not time-series)
|
||||
CREATE TABLE IF NOT EXISTS agent_state (
|
||||
agent_id UUID PRIMARY KEY REFERENCES agents(id) ON DELETE CASCADE,
|
||||
-- Network state
|
||||
network_interfaces JSONB,
|
||||
network_state_hash VARCHAR(32),
|
||||
-- Latest extended metrics (cached for quick access)
|
||||
uptime_seconds BIGINT,
|
||||
boot_time BIGINT,
|
||||
logged_in_user VARCHAR(255),
|
||||
user_idle_seconds BIGINT,
|
||||
public_ip VARCHAR(45),
|
||||
-- Timestamps
|
||||
network_updated_at TIMESTAMPTZ,
|
||||
metrics_updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Index for finding agents by public IP (useful for diagnostics)
|
||||
CREATE INDEX IF NOT EXISTS idx_agent_state_public_ip ON agent_state(public_ip);
|
||||
|
||||
-- Add memory_total_bytes and disk_total_bytes to metrics for completeness
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS memory_total_bytes BIGINT;
|
||||
ALTER TABLE metrics ADD COLUMN IF NOT EXISTS disk_total_bytes BIGINT;
|
||||
@@ -0,0 +1,30 @@
|
||||
-- Agent update tracking
|
||||
-- Tracks update commands sent to agents and their results
|
||||
|
||||
CREATE TABLE agent_updates (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
agent_id UUID NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
update_id UUID NOT NULL UNIQUE,
|
||||
old_version VARCHAR(50) NOT NULL,
|
||||
target_version VARCHAR(50) NOT NULL,
|
||||
status VARCHAR(20) DEFAULT 'pending', -- pending, downloading, installing, completed, failed, rolled_back
|
||||
download_url TEXT,
|
||||
checksum_sha256 VARCHAR(64),
|
||||
started_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
completed_at TIMESTAMPTZ,
|
||||
error_message TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Index for finding updates by agent
|
||||
CREATE INDEX idx_agent_updates_agent ON agent_updates(agent_id);
|
||||
|
||||
-- Index for finding updates by status (for monitoring)
|
||||
CREATE INDEX idx_agent_updates_status ON agent_updates(status);
|
||||
|
||||
-- Index for finding pending/in-progress updates (for timeout detection)
|
||||
CREATE INDEX idx_agent_updates_pending ON agent_updates(agent_id, status)
|
||||
WHERE status IN ('pending', 'downloading', 'installing');
|
||||
|
||||
-- Add architecture column to agents table for proper binary matching
|
||||
ALTER TABLE agents ADD COLUMN IF NOT EXISTS architecture VARCHAR(20) DEFAULT 'amd64';
|
||||
Reference in New Issue
Block a user