2023-09-09 23:38:53 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/gob"
|
|
|
|
"os"
|
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Conf struct {
|
2024-01-05 12:00:00 +01:00
|
|
|
Concurrency int `json:"concurrency"`
|
2024-03-30 17:26:10 +01:00
|
|
|
Outputs map[string]*Output `json:"outputs"`
|
2024-01-05 12:00:00 +01:00
|
|
|
Patterns map[string]*Pattern `json:"patterns"`
|
|
|
|
Streams map[string]*Stream `json:"streams"`
|
|
|
|
Start [][]string `json:"start"`
|
|
|
|
Stop [][]string `json:"stop"`
|
2023-09-09 23:38:53 +02:00
|
|
|
}
|
|
|
|
|
2024-03-30 17:26:10 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-09-09 23:38:53 +02:00
|
|
|
type Pattern struct {
|
2023-10-04 12:00:00 +02:00
|
|
|
Regex string `json:"regex"`
|
|
|
|
Ignore []string `json:"ignore"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2024-02-02 15:21:29 +01:00
|
|
|
IgnoreRegex []string `json:"ignoreregex"`
|
|
|
|
compiledIgnoreRegex []regexp.Regexp `json:"-"`
|
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
name string `json:"-"`
|
|
|
|
nameWithBraces string `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stream, Filter & Action structures must never be copied.
|
|
|
|
// They're always referenced through pointers
|
|
|
|
|
|
|
|
type Stream struct {
|
2023-10-04 12:00:00 +02:00
|
|
|
name string `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
Cmd []string `json:"cmd"`
|
|
|
|
Filters map[string]*Filter `json:"filters"`
|
2023-09-09 23:38:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Filter struct {
|
2023-10-04 12:00:00 +02:00
|
|
|
stream *Stream `json:"-"`
|
|
|
|
name string `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
Regex []string `json:"regex"`
|
|
|
|
compiledRegex []regexp.Regexp `json:"-"`
|
2024-02-24 11:42:31 +01:00
|
|
|
pattern []*Pattern `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
Retry int `json:"retry"`
|
|
|
|
RetryPeriod string `json:"retryperiod"`
|
|
|
|
retryDuration time.Duration `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
Actions map[string]*Action `json:"actions"`
|
2023-09-09 23:38:53 +02:00
|
|
|
longuestActionDuration *time.Duration
|
|
|
|
}
|
|
|
|
|
2024-03-30 17:26:10 +01:00
|
|
|
type OutputWrite struct {
|
|
|
|
OutputName string `json:"output"`
|
|
|
|
Text []string `json:"text"`
|
|
|
|
|
|
|
|
Output *Output
|
|
|
|
}
|
|
|
|
|
2023-09-09 23:38:53 +02:00
|
|
|
type Action struct {
|
2023-10-04 12:00:00 +02:00
|
|
|
filter *Filter `json:"-"`
|
|
|
|
name string `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2024-03-30 17:26:10 +01:00
|
|
|
Cmd []string `json:"cmd"`
|
|
|
|
Write *OutputWrite `json:"write"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
After string `json:"after"`
|
|
|
|
afterDuration time.Duration `json:"-"`
|
2023-09-09 23:38:53 +02:00
|
|
|
|
2023-10-04 12:00:00 +02:00
|
|
|
OnExit bool `json:"onexit"`
|
2023-09-09 23:38:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type LogEntry struct {
|
|
|
|
T time.Time
|
2023-10-21 12:00:00 +02:00
|
|
|
S int64
|
2024-02-24 11:42:31 +01:00
|
|
|
Pattern []string
|
2023-09-09 23:38:53 +02:00
|
|
|
Stream, Filter string
|
2023-10-20 12:00:00 +02:00
|
|
|
SF int
|
2023-09-09 23:38:53 +02:00
|
|
|
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{}
|
2023-09-22 18:09:31 +02:00
|
|
|
|
2023-09-24 16:44:16 +02:00
|
|
|
// Helper structs made to carry information
|
2024-02-24 11:42:31 +01:00
|
|
|
// Stream, Filter
|
2023-09-09 23:38:53 +02:00
|
|
|
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
|
|
|
|
}
|
2023-09-09 23:38:53 +02:00
|
|
|
type PF struct {
|
2024-02-24 11:42:31 +01:00
|
|
|
p []string
|
2023-09-09 23:38:53 +02:00
|
|
|
f *Filter
|
|
|
|
}
|
|
|
|
type PFT struct {
|
2024-02-24 11:42:31 +01:00
|
|
|
p []string
|
2023-09-09 23:38:53 +02:00
|
|
|
f *Filter
|
|
|
|
t time.Time
|
|
|
|
}
|
|
|
|
type PA struct {
|
2024-02-24 11:42:31 +01:00
|
|
|
p []string
|
2023-09-09 23:38:53 +02:00
|
|
|
a *Action
|
|
|
|
}
|
2023-09-22 18:09:31 +02:00
|
|
|
type PAT struct {
|
2024-02-24 11:42:31 +01:00
|
|
|
p []string
|
2023-09-22 18:09:31 +02:00
|
|
|
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
|
|
|
}
|