audit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package audit provides structured audit logging for agent operations.

All critical agent operations should be logged via this package to enable: - Security monitoring and incident response - Debugging and troubleshooting - Compliance and audit trails - Remote log collection (when configured)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextLogger

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

ContextLogger wraps Logger with context information.

func (*ContextLogger) Error

func (cl *ContextLogger) Error(eventType EventType, message string, err error, details map[string]interface{})

Error logs an error event with context.

func (*ContextLogger) Info

func (cl *ContextLogger) Info(eventType EventType, message string, details map[string]interface{})

Info logs an info event with context.

type Event

type Event struct {
	Timestamp time.Time              `json:"timestamp"`
	Type      EventType              `json:"type"`
	Severity  Severity               `json:"severity"`
	AgentID   string                 `json:"agent_id,omitempty"`
	TenantID  string                 `json:"tenant_id,omitempty"`
	JobID     string                 `json:"job_id,omitempty"`
	ReportID  string                 `json:"report_id,omitempty"`
	Message   string                 `json:"message"`
	Error     string                 `json:"error,omitempty"`
	Duration  time.Duration          `json:"duration_ms,omitempty"`
	Details   map[string]interface{} `json:"details,omitempty"`
}

Event represents an audit event.

type EventType

type EventType string

EventType represents the type of audit event.

const (
	// Lifecycle events
	EventAgentStart EventType = "agent_start"
	EventAgentStop  EventType = "agent_stop"
	EventAgentError EventType = "agent_error"

	// Job events
	EventJobReceived  EventType = "job_received"
	EventJobStarted   EventType = "job_started"
	EventJobCompleted EventType = "job_completed"
	EventJobFailed    EventType = "job_failed"
	EventJobTimeout   EventType = "job_timeout"

	// Scan events
	EventScanStarted   EventType = "scan_started"
	EventScanCompleted EventType = "scan_completed"
	EventScanFailed    EventType = "scan_failed"

	// Upload events
	EventUploadStarted   EventType = "upload_started"
	EventUploadCompleted EventType = "upload_completed"
	EventUploadFailed    EventType = "upload_failed"
	EventUploadRetry     EventType = "upload_retry"

	// Chunk events
	EventChunkCreated  EventType = "chunk_created"
	EventChunkUploaded EventType = "chunk_uploaded"
	EventChunkFailed   EventType = "chunk_failed"
	EventChunkCleanup  EventType = "chunk_cleanup"

	// Resource events
	EventResourceThrottle EventType = "resource_throttle"
	EventResourceResume   EventType = "resource_resume"
	EventResourceWarning  EventType = "resource_warning"

	// Security events
	EventAuthFailed      EventType = "auth_failed"
	EventRateLimited     EventType = "rate_limited"
	EventValidationError EventType = "validation_error"
)

type Logger

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

Logger is the audit logger.

func NewLogger

func NewLogger(config *LoggerConfig) (*Logger, error)

NewLogger creates a new audit logger.

func (*Logger) ChunkUploaded

func (l *Logger) ChunkUploaded(reportID string, chunkIndex, totalChunks int, size int)

ChunkUploaded logs a chunk upload event.

func (*Logger) Error

func (l *Logger) Error(eventType EventType, message string, err error, details map[string]interface{})

Error logs an error event.

func (*Logger) Flush

func (l *Logger) Flush()

Flush writes buffered events to disk.

func (*Logger) Info

func (l *Logger) Info(eventType EventType, message string, details map[string]interface{})

Info logs an informational event.

func (*Logger) JobCompleted

func (l *Logger) JobCompleted(jobID string, duration time.Duration, details map[string]interface{})

JobCompleted logs a job completion event.

func (*Logger) JobFailed

func (l *Logger) JobFailed(jobID string, err error, details map[string]interface{})

JobFailed logs a job failure event.

func (*Logger) JobStarted

func (l *Logger) JobStarted(jobID, jobType string, details map[string]interface{})

JobStarted logs a job start event.

func (*Logger) Log

func (l *Logger) Log(event Event)

Log records an audit event.

func (*Logger) ResourceThrottle

func (l *Logger) ResourceThrottle(reason string, metrics map[string]interface{})

ResourceThrottle logs a resource throttling event.

func (*Logger) SetRemoteSender

func (l *Logger) SetRemoteSender(sender func([]Event) error)

SetRemoteSender sets the callback for sending events to a remote endpoint.

func (*Logger) Start

func (l *Logger) Start()

Start begins background flushing.

func (*Logger) Stop

func (l *Logger) Stop() error

Stop stops the logger and flushes remaining events.

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context, jobID, reportID string) *ContextLogger

WithContext returns a context-aware logger wrapper.

type LoggerConfig

type LoggerConfig struct {
	// AgentID is the agent identifier included in all events.
	AgentID string

	// TenantID is the tenant identifier (if known).
	TenantID string

	// LogFile is the path to the audit log file.
	// Default: ~/.openctem/audit.log
	LogFile string

	// MaxSizeMB is the maximum log file size before rotation.
	// Default: 100MB
	MaxSizeMB int

	// MaxAgeDays is the maximum age of log files before deletion.
	// Default: 30 days
	MaxAgeDays int

	// RemoteEndpoint is the URL for remote log collection (optional).
	RemoteEndpoint string

	// BufferSize is the number of events to buffer before flushing.
	// Default: 100
	BufferSize int

	// FlushInterval is how often to flush buffered events.
	// Default: 5 seconds
	FlushInterval time.Duration

	// Verbose enables console output of audit events.
	Verbose bool
}

LoggerConfig configures the audit logger.

func DefaultLoggerConfig

func DefaultLoggerConfig() *LoggerConfig

DefaultLoggerConfig returns sensible defaults.

type Severity

type Severity string

Severity represents log severity level.

const (
	SeverityDebug    Severity = "DEBUG"
	SeverityInfo     Severity = "INFO"
	SeverityWarning  Severity = "WARN"
	SeverityError    Severity = "ERROR"
	SeverityCritical Severity = "CRITICAL"
)

Jump to

Keyboard shortcuts

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