chore: add logparser logic for agent and add parsed log to clickhouse
ci-agent / build (push) Failing after 3m30s

This commit is contained in:
d3m0k1d
2026-04-04 06:29:07 +03:00
parent c59d122e04
commit 477dd94227
16 changed files with 1226 additions and 409 deletions
+45
View File
@@ -0,0 +1,45 @@
package file
import (
"errors"
"os"
"gitea.d3m0k1d.ru/d3m0k1d/HellreigN/agent/internal/logsource"
"github.com/hpcloud/tail"
)
var _ logsource.LogSource = new(FileLogSource)
type FileLogSource struct {
*tail.Tail
}
func New(filepath string) (fls *FileLogSource, err error) {
if _, err := os.Stat(filepath); os.IsNotExist(err) {
if err := os.WriteFile(filepath, []byte{}, 0600); err != nil {
return nil, err
}
}
t, err := tail.TailFile(filepath, tail.Config{
Follow: true,
Location: &tail.SeekInfo{
Offset: 100,
Whence: 2,
},
})
if err != nil {
return
}
return &FileLogSource{t}, nil
}
func (f *FileLogSource) ReadLine() (string, error) {
select {
case <-f.Dead():
return "", errors.Join(logsource.ErrDead, f.Err())
case line := <-f.Lines:
return line.Text, line.Err
}
}
func (f *FileLogSource) Close() error {
return f.Stop()
}