ruleset

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ruleset handles loading and basic validation of rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadRules

func LoadRules(ruleDir string) (map[RuleID]*Rule, map[RuleID]struct{}, error)

Types

type AggDtx

type AggDtx struct {
	Match          string            `yaml:"match" validate:"required"`
	ExtMatch       []string          `yaml:"extended_match"`
	Aggregation    string            `yaml:"aggregation" validate:"required"`
	Projections    map[string]string `yaml:"projections"`
	RawGroupBy     []string          `yaml:"group_by" validate:"required,min=1"`
	Timespan       time.Duration     `yaml:"timespan" validate:"required"`
	Slide          time.Duration     `yaml:"slide"`
	Timeout        time.Duration     `yaml:"timeout"`
	EventTime      *EventTime        `yaml:"event_time"`
	EmitSuppressed bool              `yaml:"emit_suppressed"`

	GroupBy [][]string `yaml:"-"`
}

type CompositeDtx

type CompositeDtx struct {
	Timespan        time.Duration `yaml:"timespan" validate:"required"`
	TTL             time.Duration `yaml:"ttl"`
	AllowedLateness time.Duration `yaml:"allowed_lateness"`
	Timeout         time.Duration `yaml:"timeout"`
	Ordered         bool          `yaml:"ordered"`
	Parts           []Part        `yaml:"parts" validate:"required,min=2,dive"`
	EmitSuppressed  bool          `yaml:"emit_suppressed"`
}

type CompositeEventTime

type CompositeEventTime struct {
	RawField string `yaml:"field" validate:"required"`
	Layout   string `yaml:"layout" validate:"required"`

	Field []string `yaml:"-"`
}

type DecayType

type DecayType string
const (
	DecayNone   DecayType = "none"
	DecayLinear DecayType = "linear"
)

type EventDtx

type EventDtx struct {
	Match          string        `yaml:"match"  validate:"required"`
	ExtMatch       []string      `yaml:"extended_match"`
	RawTimeoutBy   []string      `yaml:"timeout_by"`
	Timeout        time.Duration `yaml:"timeout"`
	EmitSuppressed bool          `yaml:"emit_suppressed"`
	TimeoutBy      [][]string    `yaml:"-"`
}

type EventTime

type EventTime struct {
	RawField        string        `yaml:"field" validate:"required"`
	Layout          string        `yaml:"layout" validate:"required"`
	AllowedLateness time.Duration `yaml:"allowed_lateness" validate:"required"`

	Field []string `yaml:"-"`
}

type Part

type Part struct {
	Name       string              `yaml:"name" validate:"required"`
	Rule       RuleID              `yaml:"rule" validate:"required"`
	RawGroupBy []string            `yaml:"group_by" validate:"required,min=1"`
	RawStore   []string            `yaml:"store"`
	EventTime  *CompositeEventTime `yaml:"event_time"`

	GroupBy [][]string `yaml:"-"`
	Store   [][]string `yaml:"-"`
}

type RiskEntry

type RiskEntry struct {
	EntityType string        `yaml:"entity_type" validate:"required" json:"entity_type"`
	RawField   string        `yaml:"field" validate:"required" json:"field"`
	Score      float64       `yaml:"score" validate:"required,gt=0" json:"score"`
	Part       string        `yaml:"part" json:"part,omitempty"`
	Normalize  string        `yaml:"normalize" json:"normalize,omitempty"`
	Scaling    *float64      `yaml:"scaling" json:"scaling,omitempty" validate:"omitempty,gte=0,lte=1"`
	TTL        time.Duration `yaml:"ttl" json:"ttl,omitempty" validate:"gte=0"`
	Decay      DecayType     `yaml:"decay" json:"decay,omitempty" validate:"omitempty,oneof=none linear"`

	Field []string `yaml:"-" json:"-"`
}

func (*RiskEntry) EffectiveScaling

func (r *RiskEntry) EffectiveScaling() float64

type Rule

type Rule struct {
	ID          RuleID          `yaml:"id" validate:"required" json:"id"`
	Title       string          `yaml:"title" validate:"required" json:"title"`
	Type        RuleType        `yaml:"type" validate:"required,oneof=event aggregation composite" json:"type"`
	Level       RuleLevel       `yaml:"level" validate:"required,oneof=critical high medium low info" json:"level"`
	Status      RuleStatus      `yaml:"status" validate:"required,oneof=stable experimental testing deprecated" json:"status"`
	Description string          `yaml:"description" validate:"required" json:"description"`
	Tags        []string        `yaml:"tags" json:"tags,omitempty"`
	References  []string        `yaml:"references" json:"references,omitempty"`
	Alert       *bool           `yaml:"alert" json:"alert,omitempty"`
	Scopes      []string        `yaml:"scopes" json:"scopes,omitempty"`
	Risk        []RiskEntry     `yaml:"risk" json:"-"`
	Detection   yaml.RawMessage `yaml:"detection" validate:"required" json:"-"`

	File string `yaml:"-" json:"file,omitempty"`

	EventDtx     *EventDtx     `yaml:"-" json:"-"`
	AggDtx       *AggDtx       `yaml:"-" json:"-"`
	CompositeDtx *CompositeDtx `yaml:"-" json:"-"`
}

func (*Rule) AlertEnabled

func (r *Rule) AlertEnabled() bool

type RuleID

type RuleID int

type RuleLevel

type RuleLevel string
const (
	LevelCritical RuleLevel = "critical"
	LevelHigh     RuleLevel = "high"
	LevelMedium   RuleLevel = "medium"
	LevelLow      RuleLevel = "low"
	LevelInfo     RuleLevel = "info"
)

type RuleStatus

type RuleStatus string
const (
	StatusStable       RuleStatus = "stable"
	StatusExperimental RuleStatus = "experimental"
	StatusTesting      RuleStatus = "testing"
	StatusDeprecated   RuleStatus = "deprecated"
)

type RuleType

type RuleType string
const (
	TypeEvent       RuleType = "event"
	TypeAggregation RuleType = "aggregation"
	TypeComposite   RuleType = "composite"
	TypeRisk        RuleType = "risk"
)

Jump to

Keyboard shortcuts

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