feat: implement new generic parser and improve production readyness
This commit is contained in:
parent
8364218234
commit
0830b403e0
34 changed files with 1715 additions and 2114 deletions
|
|
@ -1,29 +1,23 @@
|
|||
package parser
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strings"
|
||||
"tixel_watch/helpers"
|
||||
"tixel_watch/models"
|
||||
"watch-tool/models"
|
||||
)
|
||||
|
||||
type RegexLogParser struct {
|
||||
Pattern *regexp.Regexp
|
||||
Fields map[string]string
|
||||
Toolname string
|
||||
Hostname string
|
||||
}
|
||||
|
||||
func (p *RegexLogParser) Parse(line string) (models.LogMessage, error) {
|
||||
entry := models.LogMessage{Type: "log_entry"}
|
||||
entry.Tool = p.Toolname
|
||||
entry.Raw = line
|
||||
hostname, err := helpers.GetHostname()
|
||||
if err != nil {
|
||||
slog.Warn("cannot get hostname")
|
||||
return entry, err
|
||||
}
|
||||
entry.Host = hostname
|
||||
entry.Host = p.Hostname
|
||||
|
||||
fields := p.parseWithPattern(line)
|
||||
if fields != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue