audit

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package audit provides audit logging for MCP tool calls.

Index

Constants

View Source
const (
	// MaxFileSize is the maximum size of a single audit log file before rotation.
	// Defaults to 10MB.
	MaxFileSize = 10 * 1024 * 1024

	// MaxFileAge is the maximum age of an audit log file before rotation.
	// Defaults to 7 days.
	MaxFileAge = 7 * 24 * time.Hour

	// MaxTotalSize is the maximum total size of all audit logs for an agent.
	// Defaults to 100MB.
	MaxTotalSize = 100 * 1024 * 1024
)

Rotation limits - can be customized via environment variables

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorInfo added in v1.1.0

type ErrorInfo struct {
	Timestamp string `json:"ts"`
	Action    string `json:"action"`
	Reason    string `json:"reason,omitempty"`
	OK        bool   `json:"ok"`
}

ErrorInfo represents a redacted error from audit logs.

type HealthStatus added in v1.1.0

type HealthStatus struct {
	LogFilePath     string `json:"log_file_path"`
	LogFileAge      string `json:"log_file_age"`
	LastEntryTime   string `json:"last_entry_time,omitempty"`
	Agent           string `json:"agent"`
	TotalAuditSize  int64  `json:"total_audit_size_bytes"`
	LogFileSize     int64  `json:"log_file_size_bytes"`
	ErrorCount      int    `json:"error_count_last_100"`
	LastEntryOK     *bool  `json:"last_entry_ok,omitempty"`
	OK              bool   `json:"ok"`
	WriteAccessible bool   `json:"write_accessible"`
	NeedsRotation   bool   `json:"needs_rotation"`
	NeedsRetention  bool   `json:"needs_retention"`
}

HealthStatus represents the health status of audit logging.

type LogEntry

type LogEntry struct {
	Timestamp string `json:"ts"`
	Agent     string `json:"agent"`
	Action    string `json:"action"`
	Path      string `json:"path,omitempty"`
	Field     string `json:"field,omitempty"`
	Transport string `json:"transport,omitempty"`
	Reason    string `json:"reason,omitempty"`
	DurMs     int64  `json:"dur_ms,omitempty"`
	OK        bool   `json:"ok"`
}

type Logger

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

func New

func New(agentName string) (*Logger, error)

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) EnforceRetention added in v1.1.0

func (l *Logger) EnforceRetention() error

EnforceRetention removes old rotated files to keep total audit size under MaxTotalSize.

func (*Logger) GetErrors added in v1.1.0

func (l *Logger) GetErrors(limit int) ([]ErrorInfo, error)

GetErrors returns redacted error entries from the audit log.

func (*Logger) HealthCheck added in v1.1.0

func (l *Logger) HealthCheck() (*HealthStatus, error)

HealthCheck returns the health status of the audit logger.

func (*Logger) LogEntry

func (l *Logger) LogEntry(entry LogEntry)

Jump to

Keyboard shortcuts

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