feat: Urutau 1.0.0, lightweight threat intelligence and web analytics
Release / Plan (reuse the published image?) (push) Successful in 4s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 1m29s
CI / Tests (Linux, race detector) (push) Failing after 1m48s
CI / Dependency audit (push) Successful in 21s
Release / ci (push) Failing after 1m50s
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Skipped
Release / Gitea release (push) Skipped
Release / Plan (reuse the published image?) (push) Successful in 4s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 1m29s
CI / Tests (Linux, race detector) (push) Failing after 1m48s
CI / Dependency audit (push) Successful in 21s
Release / ci (push) Failing after 1m50s
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Skipped
Release / Gitea release (push) Skipped
Always-on Go service (stdlib only) that follows the Traefik JSON access log, the sshd log and the fail2ban log of a host, classifies attacks, scores sources, keeps bounded aggregates with snapshots, and serves an embedded dashboard with live updates, offline geolocation (DB-IP Lite), privacy-friendly traffic analytics, an exportable blocklist and token-authenticated federation between instances. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
b4a2c2c9ec
99 files changed
+15403
No files matched your search
@@ -0,0 +1,74 @@
|
||||
package tail
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// copytruncate where the application regrows the file past the old offset
|
||||
// before the next poll: the size never looks smaller, the head changes.
|
||||
func TestCopytruncateRegrowIsDetected(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "a.log")
|
||||
os.WriteFile(p, []byte("l1\nl2\nl3\n"), 0o644)
|
||||
var mu sync.Mutex
|
||||
var got []string
|
||||
f := NewFollower(p, Pos{})
|
||||
f.Handle = func(b []byte) { mu.Lock(); got = append(got, string(b)); mu.Unlock() }
|
||||
f.step()
|
||||
os.WriteFile(p, []byte("n1\nn2\nn3\nn4\nn5\n"), 0o644) // truncated in place and regrown beyond offset 9
|
||||
f.step()
|
||||
f.step()
|
||||
want := []string{"l1", "l2", "l3", "n1", "n2", "n3", "n4", "n5"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("lines %v, want %v", got, want)
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("lines %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the same while the daemon was stopped: the saved position carries the fingerprint.
|
||||
func TestSavedPositionDetectsRegrownFile(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "a.log")
|
||||
os.WriteFile(p, []byte("l1\nl2\nl3\n"), 0o644)
|
||||
f := NewFollower(p, Pos{})
|
||||
f.Handle = func([]byte) {}
|
||||
f.step()
|
||||
pos := f.Pos()
|
||||
f.closeFile()
|
||||
if pos.FPLen == 0 {
|
||||
t.Fatal("the position must carry a fingerprint")
|
||||
}
|
||||
os.WriteFile(p, []byte("n1\nn2\nn3\nn4\nn5\n"), 0o644)
|
||||
var got []string
|
||||
g := NewFollower(p, pos)
|
||||
g.Handle = func(b []byte) { got = append(got, string(b)) }
|
||||
g.step()
|
||||
if len(got) != 5 || got[0] != "n1" {
|
||||
t.Fatalf("resumed in the middle of a different file: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileAppearingLaterAndAppends(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "later.log")
|
||||
var got []string
|
||||
f := NewFollower(p, Pos{})
|
||||
f.Handle = func(b []byte) { got = append(got, string(b)) }
|
||||
f.step()
|
||||
if f.Err() == nil {
|
||||
t.Fatal("an absent file is reported")
|
||||
}
|
||||
os.WriteFile(p, []byte("a\nb\n"), 0o644)
|
||||
f.step()
|
||||
fh, _ := os.OpenFile(p, os.O_APPEND|os.O_WRONLY, 0)
|
||||
fh.WriteString("c\n")
|
||||
fh.Close()
|
||||
f.step()
|
||||
if len(got) != 3 || got[2] != "c" || f.Err() != nil {
|
||||
t.Fatalf("%v %v", got, f.Err())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user