alerting

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev" // Injected via -ldflags at build time

Functions

This section is empty.

Types

type ActionTaken

type ActionTaken struct {
	Type   string `json:"type"`
	Reason string `json:"reason"`
}

type AlertEvent

type AlertEvent interface {
	EventType() string
}

type Alerter

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

func NewAlerter

func NewAlerter(cfg AlertingConfig, rdb *redis.Client) *Alerter

func (*Alerter) Close

func (a *Alerter) Close()

func (*Alerter) TriggerAuthFail

func (a *Alerter) TriggerAuthFail(ctx context.Context, requestID, reason string)

func (*Alerter) TriggerBlockAlert

func (a *Alerter) TriggerBlockAlert(ctx context.Context, requestID, keyHash, keyName, provider, model, window string, currentSpend, limit, blockedCost float64)

func (*Alerter) TriggerFailClosed

func (a *Alerter) TriggerFailClosed(ctx context.Context, requestID, reason string)

func (*Alerter) TriggerLoopAlert

func (a *Alerter) TriggerLoopAlert(ctx context.Context, requestID, keyHash, keyName, provider, sessionID, rule, detail string, blocked bool)

func (*Alerter) TriggerThresholdAlerts

func (a *Alerter) TriggerThresholdAlerts(ctx context.Context, requestID, keyHash, keyName, provider string, currentSpends map[string]float64, limits map[string]float64)

type AlertingConfig

type AlertingConfig struct {
	WebhookURL    string            `mapstructure:"webhook_url"`
	WebhookSecret string            `mapstructure:"webhook_secret"`
	BufferSize    int               `mapstructure:"buffer_size"`
	Thresholds    []ThresholdConfig `mapstructure:"thresholds"`
}

type BudgetExceededAlert

type BudgetExceededAlert struct {
	KeyHash               string  `json:"key_hash"`
	KeyName               string  `json:"key_name"`
	Provider              string  `json:"provider"`
	Model                 string  `json:"model"`
	Window                string  `json:"window"`
	CurrentSpendUSD       float64 `json:"current_spend_usd"`
	BudgetLimitUSD        float64 `json:"budget_limit_usd"`
	BlockedRequestCostUSD float64 `json:"blocked_request_cost_usd"`
}

type EventSource

type EventSource struct {
	Component string `json:"component"`
	Version   string `json:"version"`
	Instance  string `json:"instance,omitempty"`
}

type LoopDetectedAlert

type LoopDetectedAlert struct {
	KeyHash   string `json:"key_hash"`
	KeyName   string `json:"key_name"`
	Provider  string `json:"provider"`
	SessionID string `json:"session_id"`
	Rule      string `json:"rule"`
	Detail    string `json:"detail"`
	Blocked   bool   `json:"blocked"`
}

type OWASPMetadata

type OWASPMetadata struct {
	Category string `json:"owasp_category"`
	Name     string `json:"owasp_name"`
	Severity string `json:"severity"`
}

type SecurityEventEnvelope

type SecurityEventEnvelope struct {
	SchemaVersion    string        `json:"schema_version"`
	EventID          string        `json:"event_id"`
	LoopersEventType string        `json:"loopers_event_type"`
	TraceID          string        `json:"trace_id,omitempty"`
	SpanID           string        `json:"span_id,omitempty"`
	RequestID        string        `json:"request_id,omitempty"`
	Timestamp        string        `json:"timestamp"`
	Source           EventSource   `json:"source"`
	OWASP            OWASPMetadata `json:"owasp"`
	Regulation       []string      `json:"regulation,omitempty"`
	Action           ActionTaken   `json:"action"`
	Event            string        `json:"event"`
	Details          interface{}   `json:"details"`
}

SecurityEventEnvelope wraps every security event with traceability fields required by EU AI Act Article 14 (human oversight) and Article 12 (record-keeping).

func NewAuthFailEvent

func NewAuthFailEvent(ctx context.Context, requestID string, reason string, details interface{}) *SecurityEventEnvelope

func NewBudgetBlockEvent

func NewBudgetBlockEvent(ctx context.Context, requestID string, details interface{}) *SecurityEventEnvelope

func NewBudgetThresholdEvent

func NewBudgetThresholdEvent(ctx context.Context, requestID string, details interface{}) *SecurityEventEnvelope

func NewFailClosedEvent

func NewFailClosedEvent(ctx context.Context, requestID string, reason string, details interface{}) *SecurityEventEnvelope

func NewLoopBlockEvent

func NewLoopBlockEvent(ctx context.Context, requestID string, details interface{}) *SecurityEventEnvelope

func NewLoopWarnEvent

func NewLoopWarnEvent(ctx context.Context, requestID string, details interface{}) *SecurityEventEnvelope

func (*SecurityEventEnvelope) EventType

func (e *SecurityEventEnvelope) EventType() string

EventType implements the AlertEvent interface.

type ThresholdAlert

type ThresholdAlert struct {
	KeyHash          string  `json:"key_hash"`
	KeyName          string  `json:"key_name"`
	Provider         string  `json:"provider"`
	Window           string  `json:"window"`
	ThresholdPercent int     `json:"threshold_percent"`
	CurrentSpendUSD  float64 `json:"current_spend_usd"`
	BudgetLimitUSD   float64 `json:"budget_limit_usd"`
	Message          string  `json:"message"`
}

type ThresholdConfig

type ThresholdConfig struct {
	Percent float64 `mapstructure:"percent"`
	Message string  `mapstructure:"message"`
}

Jump to

Keyboard shortcuts

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