data

package
v0.0.0-...-a4e6c2a Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogVerdictUnknown int = iota
	LogVerdictHam
	LogVerdictSpam
	LogVerdictNothing
	NumLogVerdicts
)

Variables

View Source
var ErrHashNotFound = errors.New("specified hash not found")
View Source
var ErrRuleNotFound = errors.New("specified rule not found")

Functions

func LogMatchesRule

func LogMatchesRule(log *Log, rule *LogRule) bool

func LogRuleToVerdict

func LogRuleToVerdict(rule *LogRule) int

func LogVerdict

func LogVerdict(log *Log, rules []*LogRule) int

func LogVerdictToString

func LogVerdictToString(verdict int) string

func SortedKeys

func SortedKeys[K cmp.Ordered, V any](m map[string]V) []string

func SortedKeysWithFunc

func SortedKeysWithFunc[K comparable, V any](m map[K]V, cmp func(a, b K) int) []K

Types

type Database

type Database struct {

	// TODO: There should be really locking here too?
	// log fetching is probably the more common thing though
	LogRules *LogRules
	// contains filtered or unexported fields
}

func NewDatabaseFromFile

func NewDatabaseFromFile(config DatabaseConfig, path string) (db *Database, err error)

func (*Database) Add

func (self *Database) Add(r LogRule) error

func (*Database) ClassifyHash

func (self *Database) ClassifyHash(hash uint64, ham bool) error

func (*Database) Delete

func (self *Database) Delete(rid int) error

func (*Database) Logs

func (self *Database) Logs() []*Log

func (*Database) RuleCount

func (self *Database) RuleCount(rid int) int

func (*Database) Save

func (self *Database) Save(rules []*LogRule) error

type DatabaseConfig

type DatabaseConfig struct {
	LokiServer   string
	LokiSelector string
}

type Log

type Log struct {
	Timestamp  int64
	Time       time.Time
	Stream     map[string]string
	StreamKeys []string
	Fields     map[string]interface{}
	FieldsKeys []string
	Message    string
	RawMessage string
	// contains filtered or unexported fields
}

func NewLog

func NewLog(timestamp int64, stream map[string]string, data string) *Log

func (*Log) Hash

func (self *Log) Hash() uint64

func (*Log) IDString

func (self *Log) IDString() string

func (*Log) MatchesFTS

func (self *Log) MatchesFTS(search string) bool

func (*Log) ToRule

func (self *Log) ToRule(rules *LogRules) *LogRule

type LogFieldMatcher

type LogFieldMatcher struct {
	Field string
	Op    string
	Value string
	// contains filtered or unexported fields
}

func (*LogFieldMatcher) Match

func (self *LogFieldMatcher) Match(s string) bool

func (*LogFieldMatcher) MatchesFTS

func (self *LogFieldMatcher) MatchesFTS(s string) bool

type LogRule

type LogRule struct {
	// Id zero is reserved 'not saved'
	ID int

	// Rule may or may not be disabled
	Disabled bool

	// Is the result interesting, or not?
	Ham bool

	// List of matchers the rule matches against
	Matchers []LogFieldMatcher

	// Comment (if any)
	Comment string

	// Version of the rule; any time the rule is changed, the
	// version is incremented
	Version int
}

func LogToRule

func LogToRule(log *Log, rules []*LogRule) *LogRule

func (*LogRule) MatchesFTS

func (self *LogRule) MatchesFTS(search string) bool

type LogRules

type LogRules struct {
	Rules   []*LogRule
	Version int

	// Reversed rules - these are always available if Rules are
	Reversed []*LogRule `json:"-"`
	// contains filtered or unexported fields
}

func NewLogRules

func NewLogRules(rules []*LogRule, version int) *LogRules

type LokiQueryResult

type LokiQueryResult struct {
	Status string               `json:"status"`
	Data   *LokiQueryResultData `json:"data"`
}

type LokiQueryResultData

type LokiQueryResultData struct {
	ResultType string                      `json:"resultType"`
	Result     []LokiQueryResultDataResult `json:"result"`
}

type LokiQueryResultDataResult

type LokiQueryResultDataResult struct {
	Metric map[string]string `json:"metric"`
	Stream map[string]string `json:"stream"`
	Values [][]string        `json:"values"`
}

Jump to

Keyboard shortcuts

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