audit

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category 操作类别

const (
	CatAuth    Category = "AUTH"
	CatConfig  Category = "CONFIG"
	CatData    Category = "DATA"
	CatTool    Category = "TOOL"
	CatSkill   Category = "SKILL"
	CatSession Category = "SESSION"
	CatPlugin  Category = "PLUGIN"
	CatSystem  Category = "SYSTEM"
	CatNetwork Category = "NETWORK"
)

type Entry

type Entry struct {
	ID         string                 `json:"id"`
	Timestamp  time.Time              `json:"timestamp"`
	Level      Level                  `json:"level"`
	Category   Category               `json:"category"`
	Action     string                 `json:"action"`
	Actor      string                 `json:"actor"`
	Resource   string                 `json:"resource"`
	Result     string                 `json:"result"` // success, failure, partial
	StatusCode int                    `json:"status_code,omitempty"`
	Error      string                 `json:"error,omitempty"`
	IPAddress  string                 `json:"ip_address,omitempty"`
	UserAgent  string                 `json:"user_agent,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	SessionID  string                 `json:"session_id,omitempty"`
	Duration   time.Duration          `json:"duration,omitempty"`
}

Entry 审计条目

type Level

type Level string

Level 审计级别

const (
	LevelInfo  Level = "INFO"
	LevelWarn  Level = "WARN"
	LevelError Level = "ERROR"
	LevelAudit Level = "AUDIT"
)

type Manager

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

Manager 审计管理器

func NewManager

func NewManager(dataDir string) (*Manager, error)

NewManager creates audit manager

func (*Manager) Close

func (m *Manager) Close() error

Close 关闭管理器

func (*Manager) Export

func (m *Manager) Export(start, end time.Time, format string) ([]byte, error)

Export 导出审计记录

func (*Manager) GetByID

func (m *Manager) GetByID(id string) *Entry

GetByID 根据 ID 获取条目

func (*Manager) GetRecent

func (m *Manager) GetRecent(limit int) []*Entry

GetRecent 获取最近的条目

func (*Manager) GetStats

func (m *Manager) GetStats(start, end time.Time) (*Stats, error)

GetStats 获取统计信息

func (*Manager) Log

func (m *Manager) Log(level Level, category Category, action, actor, resource, result string, opts ...Option) *Entry

Log 记录审计条目

func (*Manager) LogAuth

func (m *Manager) LogAuth(action, actor, result string, err error) *Entry

LogAuth 记录认证事件

func (*Manager) LogConfig

func (m *Manager) LogConfig(action, actor, resource, result string) *Entry

LogConfig 记录配置变更

func (*Manager) LogData

func (m *Manager) LogData(action, actor, resource, result string, metadata map[string]interface{}) *Entry

LogData 记录数据操作

func (*Manager) LogError

func (m *Manager) LogError(category Category, action, resource, errMsg string) *Entry

LogError 记录错误

func (*Manager) LogPlugin

func (m *Manager) LogPlugin(action, name, result string, err error) *Entry

LogPlugin 记录插件事件

func (*Manager) LogSession

func (m *Manager) LogSession(action, sessionID, result string) *Entry

LogSession 记录会话事件

func (*Manager) LogSkill

func (m *Manager) LogSkill(action, name, result string) *Entry

LogSkill 记录技能操作

func (*Manager) LogSystem

func (m *Manager) LogSystem(action, result string, metadata map[string]interface{}) *Entry

LogSystem 记录系统事件

func (*Manager) LogTool

func (m *Manager) LogTool(name, result string, duration time.Duration, err error) *Entry

LogTool 记录工具执行

func (*Manager) Query

func (m *Manager) Query(q *Query) ([]*Entry, error)

Query 查询审计记录

type Option

type Option func(*Entry)

Option 审计条目选项

func WithDuration

func WithDuration(d time.Duration) Option

WithDuration 设置持续时间

func WithError

func WithError(err error) Option

WithError 设置错误

func WithIP

func WithIP(ip string) Option

WithIP 设置 IP 地址

func WithMetadata

func WithMetadata(metadata map[string]interface{}) Option

WithMetadata 设置元数据

func WithSession

func WithSession(sessionID string) Option

WithSession 设置会话 ID

func WithStatusCode

func WithStatusCode(code int) Option

WithStatusCode 设置状态码

type Query

type Query struct {
	StartTime time.Time
	EndTime   time.Time
	Level     Level
	Category  Category
	Action    string
	Actor     string
	Resource  string
	Result    string
	Limit     int
	Offset    int
}

Query 查询条件

type Stats

type Stats struct {
	Total      int              `json:"total"`
	Errors     int              `json:"errors"`
	ByLevel    map[Level]int    `json:"by_level"`
	ByCategory map[Category]int `json:"by_category"`
	ByResult   map[string]int   `json:"by_result"`
}

Stats 统计信息

Jump to

Keyboard shortcuts

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