reaction/app/types.go

145 lines
2.8 KiB
Go
Raw Normal View History

package app
import (
"encoding/gob"
"os"
"regexp"
"time"
)
type Conf struct {
Concurrency int `json:"concurrency"`
Outputs map[string]*Output `json:"outputs"`
Patterns map[string]*Pattern `json:"patterns"`
Streams map[string]*Stream `json:"streams"`
Start [][]string `json:"start"`
Stop [][]string `json:"stop"`
}
type Output struct {
Start []string `json:"start"`
Stop []string `json:"stop"`
// TODO: Restart when lost communication with output
//Restart string `json:"restart"`
name string `json:"-"`
Stdin chan string
}
type Pattern struct {
Regex string `json:"regex"`
Ignore []string `json:"ignore"`
IgnoreRegex []string `json:"ignoreregex"`
compiledIgnoreRegex []regexp.Regexp `json:"-"`
name string `json:"-"`
nameWithBraces string `json:"-"`
}
// Stream, Filter & Action structures must never be copied.
// They're always referenced through pointers
type Stream struct {
name string `json:"-"`
Cmd []string `json:"cmd"`
Filters map[string]*Filter `json:"filters"`
}
type Filter struct {
stream *Stream `json:"-"`
name string `json:"-"`
Regex []string `json:"regex"`
compiledRegex []regexp.Regexp `json:"-"`
2024-02-24 11:42:31 +01:00
pattern []*Pattern `json:"-"`
Retry int `json:"retry"`
RetryPeriod string `json:"retryperiod"`
retryDuration time.Duration `json:"-"`
Actions map[string]*Action `json:"actions"`
longuestActionDuration *time.Duration
}
type OutputWrite struct {
OutputName string `json:"output"`
Text []string `json:"text"`
Output *Output
}
type Action struct {
filter *Filter `json:"-"`
name string `json:"-"`
Cmd []string `json:"cmd"`
Write *OutputWrite `json:"write"`
After string `json:"after"`
afterDuration time.Duration `json:"-"`
OnExit bool `json:"onexit"`
}
type LogEntry struct {
T time.Time
S int64
2024-02-24 11:42:31 +01:00
Pattern []string
Stream, Filter string
SF int
Exec bool
}
type ReadDB struct {
file *os.File
dec *gob.Decoder
}
type WriteDB struct {
file *os.File
enc *gob.Encoder
}
2024-02-24 11:42:31 +01:00
// https://stackoverflow.com/a/69691894
type MatchesMap map[*PF]map[time.Time]struct{}
type ActionsMap map[*PA]map[time.Time]struct{}
// Helper structs made to carry information
2024-02-24 11:42:31 +01:00
// Stream, Filter
type SF struct{ s, f string }
2024-02-24 11:42:31 +01:00
// Pattern, Stream, Filter
type PSF struct{
p []string
s string
f string
}
type PF struct {
2024-02-24 11:42:31 +01:00
p []string
f *Filter
}
type PFT struct {
2024-02-24 11:42:31 +01:00
p []string
f *Filter
t time.Time
}
type PA struct {
2024-02-24 11:42:31 +01:00
p []string
a *Action
}
type PAT struct {
2024-02-24 11:42:31 +01:00
p []string
a *Action
t time.Time
}
2023-10-01 12:00:00 +02:00
type FlushMatchOrder struct {
2024-02-24 11:42:31 +01:00
p []string
2023-10-04 12:00:00 +02:00
ret chan MatchesMap
2023-10-01 12:00:00 +02:00
}
type FlushActionOrder struct {
2024-02-24 11:42:31 +01:00
p []string
2023-10-04 12:00:00 +02:00
ret chan ActionsMap
2023-10-01 12:00:00 +02:00
}