refactor: move models to their own package to use the same as in the importer
This commit is contained in:
parent
553a85562b
commit
9aa1b7384d
14 changed files with 170 additions and 152 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tixel_watch/models"
|
||||
|
||||
"github.com/hpcloud/tail"
|
||||
)
|
||||
|
|
@ -17,7 +18,7 @@ type FileMonitor struct {
|
|||
}
|
||||
|
||||
type LogParser interface {
|
||||
Parse(line string, toolName string) LogEntry
|
||||
Parse(line string, toolName string) models.LogMessage
|
||||
}
|
||||
|
||||
func NewFileMonitor(config ToolConfig) *FileMonitor {
|
||||
|
|
@ -49,7 +50,7 @@ func NewFileMonitor(config ToolConfig) *FileMonitor {
|
|||
}
|
||||
}
|
||||
|
||||
func (fm *FileMonitor) Start(ctx context.Context, out chan<- LogEntry) error {
|
||||
func (fm *FileMonitor) Start(ctx context.Context, out chan<- models.LogMessage) error {
|
||||
t, err := tail.TailFile(fm.config.LogFile, tail.Config{
|
||||
Follow: true,
|
||||
ReOpen: true,
|
||||
|
|
@ -98,8 +99,8 @@ func (fm *FileMonitor) Start(ctx context.Context, out chan<- LogEntry) error {
|
|||
|
||||
type DefaultLogParser struct{}
|
||||
|
||||
func (p *DefaultLogParser) Parse(line string, toolName string) LogEntry {
|
||||
entry := NewLogEntry("log_entry")
|
||||
func (p *DefaultLogParser) Parse(line string, toolName string) models.LogMessage {
|
||||
entry := models.NewLogMessage("log_entry", hostname)
|
||||
entry.Tool = toolName
|
||||
entry.LogMessage = strings.TrimSpace(line)
|
||||
entry.Raw = line
|
||||
|
|
@ -111,8 +112,8 @@ type RegexLogParser struct {
|
|||
fields map[string]string
|
||||
}
|
||||
|
||||
func (p *RegexLogParser) Parse(line string, toolName string) LogEntry {
|
||||
entry := NewLogEntry("log_entry")
|
||||
func (p *RegexLogParser) Parse(line string, toolName string) models.LogMessage {
|
||||
entry := models.NewLogMessage("log_entry", hostname)
|
||||
entry.Tool = toolName
|
||||
entry.Raw = line
|
||||
|
||||
|
|
@ -156,17 +157,17 @@ func (p *RegexLogParser) parseWithPattern(text string) map[string]any {
|
|||
|
||||
type NginxTJMLogParser struct{}
|
||||
|
||||
func (p *NginxTJMLogParser) Parse(line string, toolName string) LogEntry {
|
||||
entry := NewLogEntry("log_entry")
|
||||
func (p *NginxTJMLogParser) Parse(line string, toolName string) models.LogMessage {
|
||||
entry := models.NewLogMessage("log_entry", hostname)
|
||||
entry.Tool = toolName
|
||||
entry.Raw = line
|
||||
entry = p.parseNginxTJM(entry)
|
||||
return entry
|
||||
}
|
||||
|
||||
func (p *NginxTJMLogParser) parseNginxTJM(entry LogEntry) LogEntry {
|
||||
func (p *NginxTJMLogParser) parseNginxTJM(entry models.LogMessage) models.LogMessage {
|
||||
newEntry := entry
|
||||
var nginxBase NGinXBaseInfo
|
||||
var nginxBase models.NGinXBaseInfo
|
||||
parts := strings.Fields(entry.Raw)
|
||||
if len(parts) < 10 {
|
||||
return newEntry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue