add sources
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
-- AtlasOS - Calypso
|
||||
-- Migration 015: Add Bacula clients and capability history tables
|
||||
--
|
||||
-- Adds tables for tracking registered Bacula agents, their backup capabilities,
|
||||
-- and a history log for UI- or agent-triggered capability changes. Pending
|
||||
-- updates are stored on the client row until the agent pulls them.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bacula_clients (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hostname TEXT NOT NULL,
|
||||
ip_address TEXT,
|
||||
agent_version TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'online',
|
||||
backup_types JSONB NOT NULL,
|
||||
pending_backup_types JSONB,
|
||||
pending_requested_by UUID,
|
||||
pending_requested_at TIMESTAMPTZ,
|
||||
pending_notes TEXT,
|
||||
metadata JSONB,
|
||||
registered_by_user_id UUID NOT NULL,
|
||||
last_seen TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT uniq_bacula_clients_hostname UNIQUE (hostname)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bacula_clients_registered_by ON bacula_clients (registered_by_user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_bacula_clients_status ON bacula_clients (status);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bacula_client_capability_history (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
client_id UUID NOT NULL REFERENCES bacula_clients (id) ON DELETE CASCADE,
|
||||
backup_types JSONB NOT NULL,
|
||||
source TEXT NOT NULL,
|
||||
requested_by_user_id UUID,
|
||||
requested_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
notes TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bacula_client_capability_history_client ON bacula_client_capability_history (client_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_bacula_client_capability_history_requested_at ON bacula_client_capability_history (requested_at);
|
||||
|
||||
COMMENT ON TABLE bacula_clients IS 'Tracks Bacula clients registered with Calypso, including pending capability pushes.';
|
||||
COMMENT ON TABLE bacula_client_capability_history IS 'Audit history of backup capability changes per client.';
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/atlasos/calypso/internal/audit"
|
||||
"github.com/atlasos/calypso/internal/auth"
|
||||
"github.com/atlasos/calypso/internal/backup"
|
||||
"github.com/atlasos/calypso/internal/bacula"
|
||||
|
||||
"github.com/atlasos/calypso/internal/common/cache"
|
||||
"github.com/atlasos/calypso/internal/common/config"
|
||||
"github.com/atlasos/calypso/internal/common/database"
|
||||
@@ -457,6 +459,18 @@ func NewRouter(cfg *config.Config, db *database.DB, log *logger.Logger) *gin.Eng
|
||||
backupGroup.POST("/console/execute", requirePermission("backup", "write"), backupHandler.ExecuteBconsoleCommand)
|
||||
}
|
||||
|
||||
baculaHandler := bacula.NewHandler(db, log)
|
||||
baculaGroup := protected.Group("/bacula/clients")
|
||||
baculaGroup.Use(requireRole("bacula-admin"))
|
||||
{
|
||||
baculaGroup.POST("/register", baculaHandler.Register)
|
||||
baculaGroup.POST("/:id/capabilities", baculaHandler.UpdateCapabilities)
|
||||
baculaGroup.GET("/:id/pending-update", baculaHandler.GetPendingUpdate)
|
||||
baculaGroup.POST("/:id/ping", baculaHandler.Ping)
|
||||
baculaGroup.GET("", baculaHandler.ListClients)
|
||||
baculaGroup.GET("/:id", baculaHandler.GetClient)
|
||||
}
|
||||
|
||||
// Monitoring
|
||||
monitoringHandler := monitoring.NewHandler(db, log, alertService, metricsService, eventHub)
|
||||
monitoringGroup := protected.Group("/monitoring")
|
||||
|
||||
Reference in New Issue
Block a user