engine

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendTemplateOIDs

func AppendTemplateOIDs(templateID string, oids []TemplateOID)

AppendTemplateOIDs adds OIDs to an existing device template by ID.

func TenantIDFromContext

func TenantIDFromContext(ctx context.Context) string

TenantIDFromContext extracts the tenant ID from a request context. Returns "default" if no tenant ID is set.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine wraps all application components and manages the lifecycle. Usage: New() -> (optional Registry().Register overrides) -> Init() -> Run()

func New

func New(ctx context.Context) (*Engine, error)

New creates a new Engine, loading config, connecting to the database, creating all repositories, services, notifiers, and registering default modules. It does NOT call InitAll or start the server, allowing callers to register module overrides before initialization.

func (*Engine) AddHeartbeatHook

func (e *Engine) AddHeartbeatHook(hook HeartbeatHook)

AddHeartbeatHook registers a hook to be called after each heartbeat is processed. Extensions can use this for post-processing heartbeat data.

func (*Engine) AgentAuthService

func (e *Engine) AgentAuthService() ports.AgentAuthService

AgentAuthService returns the agent auth service for extensions.

func (*Engine) AgentMessenger

func (e *Engine) AgentMessenger() ports.AgentMessenger

AgentMessenger returns the WebSocket hub as an AgentMessenger for extensions.

func (*Engine) AgentRepo

func (e *Engine) AgentRepo() ports.AgentRepository

AgentRepo returns the agent repository for extensions.

func (*Engine) AuditService

func (e *Engine) AuditService() ports.AuditService

AuditService returns the audit service for extensions.

func (*Engine) AuthMiddleware

func (e *Engine) AuthMiddleware() echo.MiddlewareFunc

AuthMiddleware returns an Echo middleware that authenticates requests via session cookie and sets "user_id" in the Echo context. This is exposed so that external route groups (which cannot import internal packages) can reuse the same session-based auth that CE uses. Returns JSON 401 on failure.

func (*Engine) CertDetailsRepo

func (e *Engine) CertDetailsRepo() ports.CertDetailsRepository

CertDetailsRepo returns the certificate details repository for extensions.

func (*Engine) Echo

func (e *Engine) Echo() *echo.Echo

Echo returns the underlying Echo instance for route extensions.

func (*Engine) HeartbeatRepo

func (e *Engine) HeartbeatRepo() ports.HeartbeatRepository

HeartbeatRepo returns the heartbeat repository for extensions.

func (*Engine) IncidentRepo

func (e *Engine) IncidentRepo() ports.IncidentRepository

IncidentRepo returns the incident repository for extensions.

func (*Engine) IncidentService

func (e *Engine) IncidentService() ports.IncidentService

IncidentService returns the incident service for extensions.

func (*Engine) Init

func (e *Engine) Init(ctx context.Context) error

Init initializes all registered modules and registers HTTP routes. Call this after registering any module overrides.

func (*Engine) InvestigationService

func (e *Engine) InvestigationService() ports.InvestigationService

InvestigationService returns the investigation service for extensions.

func (*Engine) Logger

func (e *Engine) Logger() *slog.Logger

Logger returns the configured logger.

func (*Engine) MonitorRepo

func (e *Engine) MonitorRepo() ports.MonitorRepository

MonitorRepo returns the monitor repository for extensions.

func (*Engine) MonitorService

func (e *Engine) MonitorService() ports.MonitorService

MonitorService returns the monitor service for extensions.

func (*Engine) NewMaintenanceWindowRepo

func (e *Engine) NewMaintenanceWindowRepo() ports.MaintenanceWindowRepository

NewMaintenanceWindowRepo returns the maintenance window repository. The repo is already wired into MonitorService during New(). Kept for compatibility.

func (*Engine) OnMaintenanceExpired

func (e *Engine) OnMaintenanceExpired(hook MaintenanceExpiredHook)

OnMaintenanceExpired registers a hook called when a maintenance window expires with an offline agent. EE uses this for audit logging.

func (*Engine) Pool

func (e *Engine) Pool() *pgxpool.Pool

Pool returns the underlying database connection pool.

func (*Engine) Registry

func (e *Engine) Registry() *registry.Registry

Registry returns the module registry for registering overrides.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

Run starts the HTTP server and blocks until SIGINT/SIGTERM.

func (*Engine) SetIncidents

func (e *Engine) SetIncidents(open, acknowledged int)

SetIncidents updates the Prometheus incidents_active gauge.

func (*Engine) SetMaintenanceTenantProvider

func (e *Engine) SetMaintenanceTenantProvider(p MaintenanceTenantProvider)

SetMaintenanceTenantProvider sets the provider for listing tenant IDs. When set, the background maintenance ticker iterates over all tenants instead of only the "default" tenant. EE sets this from the tenants table.

func (*Engine) SetPostRegisterHook

func (e *Engine) SetPostRegisterHook(hook handlers.PostRegisterHook)

SetPostRegisterHook sets the hook for post-registration actions.

func (*Engine) SetRateLimitOnReject

func (e *Engine) SetRateLimitOnReject(fn func(ip string))

SetRateLimitOnReject sets the callback that the general rate limiter will invoke whenever a request is denied for exceeding the burst limit. The callback receives the client IP string. Pass nil to clear.

Must be called before Init() — the router constructs the limiter during Init and the callback value is captured at that point.

Use case: extension modules wire this to persistent block-list trackers (e.g. write to a blocked_ips table) without modifying the rate-limiter or middleware code paths.

func (*Engine) SetTenantValidator

func (e *Engine) SetTenantValidator(v handlers.TenantValidator)

SetTenantValidator sets the hook for tenant-scoped registration. When set, registration requires a valid tenant_slug and creates users in the specified tenant rather than the default.

func (*Engine) Shutdown

func (e *Engine) Shutdown(ctx context.Context) error

Shutdown performs graceful shutdown of all components.

func (*Engine) StatusPageRepo

func (e *Engine) StatusPageRepo() ports.StatusPageRepository

StatusPageRepo returns the status page repository for extensions.

func (*Engine) TenantMiddleware

func (e *Engine) TenantMiddleware() echo.MiddlewareFunc

TenantMiddleware returns the tenant-scoping middleware that injects tenant_id into the request context. External route groups need this to ensure repository queries are correctly scoped by tenant.

type HeartbeatHook

type HeartbeatHook func(ctx context.Context, agentID, monitorID uuid.UUID, payload *protocol.HeartbeatPayload)

HeartbeatHook is called after each heartbeat is processed. Extensions can use this to add custom post-processing.

type MaintenanceExpiredHook

type MaintenanceExpiredHook func(ctx context.Context, mw *domain.MaintenanceWindow)

MaintenanceExpiredHook is called when a maintenance window expires with an offline agent. Extensions (e.g. EE) can use this for audit logging.

type MaintenanceTenantProvider

type MaintenanceTenantProvider func(ctx context.Context) []string

MaintenanceTenantProvider returns all tenant IDs that have maintenance windows. Used by the background ticker to iterate over tenants for RLS-safe queries. If nil, only the "default" tenant is processed.

type TemplateOID

type TemplateOID struct {
	OID       string
	Name      string
	Unit      string
	Category  string
	IsCounter bool
}

TemplateOID describes an SNMP OID to add to a device template.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL