fix: 1.4.4 read Traefik text logs, degraded source alert, mobile menu
Release / Publish tags (push) Successful in 16s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 1m46s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 23s
CI / Format and vet (push) Successful in 24s
CI / Tests (Linux, race detector) (push) Successful in 1m22s
CI / Dependency audit (push) Successful in 27s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 4s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 01:20:03 -03:00
1 parent 50cd2bd3ce
commit 0dc3268b29
13 files changed
+297 -9

No files matched your search

+8
View File
@@ -6,6 +6,14 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versio
## [Unreleased]
## [1.4.4] - 2026-11-15
### Fixed
- Traefik access logs in the default text format are now read too (fewer fields than JSON: no host or service), so a proxy that loses its JSON setting no longer silently drops the web traffic.
- A source with more than 20% unreadable lines in its last 1000 is shown as degraded (red) in Integrity and Sources, logged once an hour, and checked by `urutau doctor`.
- Mobile: the More menu scrolls when it is taller than the screen.
## [1.4.3] - 2026-11-15
### Added
+8
View File
@@ -6,6 +6,14 @@ Formato baseado no [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/);
## [Unreleased]
## [1.4.4] - 2026-11-15
### Corrigido
- O log de acesso do Traefik no formato texto padrão agora também é lido (menos campos que o JSON: sem host nem serviço), então um proxy que perde a configuração JSON não descarta mais o tráfego web em silêncio.
- Uma fonte com mais de 20% de linhas ilegíveis nas últimas 1000 aparece como degradada (vermelho) em Integridade e Fontes, é registrada no log uma vez por hora e é verificada pelo `urutau doctor`.
- Celular: o menu Mais rola quando é maior que a tela.
## [1.4.3] - 2026-11-15
### Adicionado
+50
View File
@@ -1,10 +1,13 @@
package app
import (
"bytes"
"errors"
"time"
"encoding/json"
"fmt"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/geo"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
"io"
@@ -46,6 +49,11 @@ func Doctor(c Config, w io.Writer, asJSON bool) bool {
fi, _ := f.Stat()
f.Close()
add("source "+s.name, "ok", fmt.Sprintf("%s readable (%d bytes)", s.path, fi.Size()))
if s.name == "traefik" {
if bad, n := sampleMalformed(s.path); n >= winMin && bad*5 > n {
add("source traefik format", "warn", fmt.Sprintf("degraded: %d of the last %d lines are malformed: %s", bad, n, degradedMsg))
}
}
}
if err := os.MkdirAll(c.DataDir, 0o700); err != nil {
add("data-dir", "fail", err.Error())
@@ -134,3 +142,45 @@ func doctorState(c Config, add func(name, status, detail string)) map[string]any
add("state", "ok", fmt.Sprintf("%d IPs, %d domains, %d requests in 7 days", st.IPCount(), len(tr.Domains), tr.Requests))
return info
}
// sampleMalformed parses up to the last winSize lines of a Traefik log and
// counts the malformed ones.
func sampleMalformed(path string) (bad, n int) {
f, err := os.Open(path)
if err != nil {
return 0, 0
}
defer f.Close()
const tailBytes = 512 << 10
off := int64(0)
if fi, err := f.Stat(); err == nil && fi.Size() > tailBytes {
off = fi.Size() - tailBytes
}
if _, err := f.Seek(off, io.SeekStart); err != nil {
return 0, 0
}
b, err := io.ReadAll(io.LimitReader(f, tailBytes))
if err != nil {
return 0, 0
}
lines := bytes.Split(b, []byte("\n"))
if off > 0 && len(lines) > 0 {
lines = lines[1:] // first line is cut
}
if len(lines) > 0 && len(lines[len(lines)-1]) == 0 {
lines = lines[:len(lines)-1]
}
if len(lines) > winSize {
lines = lines[len(lines)-winSize:]
}
for _, l := range lines {
if len(bytes.TrimSpace(l)) == 0 {
continue
}
n++
if _, err := core.ParseTraefik(l); err != nil && !errors.Is(err, core.ErrIgnored) {
bad++
}
}
return bad, n
}
+53 -1
View File
@@ -23,6 +23,8 @@ type source struct {
parse func([]byte) (core.Event, error)
lines, malformed atomic.Uint64
win window
lastWarn atomic.Int64
lastEvent atomic.Int64
backfilling atomic.Bool
fol atomic.Pointer[tail.Follower]
@@ -32,6 +34,44 @@ func traefikParse(b []byte) (core.Event, error) { return core.ParseTraefik(b) }
func authParse(b []byte) (core.Event, error) { return core.ParseAuth(string(b)) }
func f2bParse(b []byte) (core.Event, error) { return core.ParseFail2ban(string(b)) }
const (
winSize = 1000
winMin = 50 // fewer samples than this never mark a source degraded
degradedMsg = "formato inesperado (JSON esperado?)"
)
// window remembers whether each of the last winSize lines was malformed.
type window struct {
mu sync.Mutex
ring [winSize]bool
n int // lines recorded so far, capped at winSize
pos int
bad int
}
func (w *window) add(bad bool) {
w.mu.Lock()
defer w.mu.Unlock()
if w.n == winSize && w.ring[w.pos] {
w.bad--
}
w.ring[w.pos] = bad
if bad {
w.bad++
}
w.pos = (w.pos + 1) % winSize
if w.n < winSize {
w.n++
}
}
// degraded reports whether more than 20% of the recent lines were malformed.
func (w *window) degraded() bool {
w.mu.Lock()
defer w.mu.Unlock()
return w.n >= winMin && w.bad*5 > w.n
}
func (s *source) status() store.SourceStatus {
st := store.SourceStatus{Name: s.name, Path: s.path, Lines: s.lines.Load(), Malformed: s.malformed.Load(),
LastEvent: s.lastEvent.Load(), State: "following"}
@@ -55,6 +95,9 @@ func (s *source) status() store.SourceStatus {
}
}
}
if st.State == "following" && s.win.degraded() {
st.State, st.Error = "degraded", degradedMsg
}
return st
}
@@ -148,11 +191,20 @@ func (r *Runner) handle(s *source) func([]byte) {
s.lines.Add(1)
ev, err := s.parse(line)
if err != nil {
if !errors.Is(err, core.ErrIgnored) {
bad := !errors.Is(err, core.ErrIgnored)
if bad {
s.malformed.Add(1)
}
s.win.add(bad)
if bad && s.win.degraded() {
now := time.Now().Unix()
if last := s.lastWarn.Load(); now-last >= 3600 && s.lastWarn.CompareAndSwap(last, now) {
r.Log.Warn("many lines of this source are malformed", "source", s.name, "detail", degradedMsg)
}
}
return
}
s.win.add(false)
if core.Ignored(r.Ignore, ev.IP) {
return
}
+22
View File
@@ -257,3 +257,25 @@ func TestEgressExtraAllow(t *testing.T) {
t.Fatalf("%v", s)
}
}
func TestSourceDegradedWindow(t *testing.T) {
var w window
for i := 0; i < 100; i++ {
w.add(i%10 == 0)
}
if w.degraded() {
t.Fatal("10% must not degrade")
}
for i := 0; i < 400; i++ {
w.add(true)
}
if !w.degraded() {
t.Fatal("expected degraded")
}
for i := 0; i < winSize; i++ {
w.add(false)
}
if w.degraded() {
t.Fatal("window must recover")
}
}
+1 -1
View File
@@ -2,4 +2,4 @@ package app
// Version is the release version (SemVer). Release builds may override it with
// -ldflags "-X .../internal/app.Version=...".
var Version = "1.4.3"
var Version = "1.4.4"
+22
View File
@@ -266,3 +266,25 @@ func TestZonesAreRejectedEverywhere(t *testing.T) {
}
_ = strings.ToLower
}
func TestParseTraefikText(t *testing.T) {
ev, err := ParseTraefik([]byte(`10.0.15.1 - - [15/Nov/2026:04:10:51 +0000] "GET /wp-content/uploads/2026/08/IMG.jpg HTTP/2.0" 200 252131 "-" "-" 22219 "https-0-fwl1r20xzp8uf2g48log9q49-wordpress-1870@docker" "http://10.0.5.2:80" 3ms`))
if err != nil {
t.Fatal(err)
}
if ev.IP != "10.0.15.1" || ev.Method != "GET" || ev.Path != "/wp-content/uploads/2026/08/IMG.jpg" || ev.Proto != "HTTP/2.0" ||
ev.Status != 200 || ev.Bytes != 252131 || ev.UA != "" || ev.Referer != "" || ev.OriginStatus != 200 ||
ev.DurationNS != 3e6 || ev.Domain != "" || ev.Router != "https-0-fwl1r20xzp8uf2g48log9q49-wordpress-1870@docker" ||
ev.Time.Format("2006-01-02T15:04:05Z") != "2026-11-15T04:10:51Z" {
t.Fatalf("%+v", ev)
}
ev, err = ParseTraefik([]byte(`203.0.113.9 - - [15/Nov/2026:04:10:52 +0000] "POST /wp-login.php HTTP/1.1" 404 19 "https://x/\"y" "Mozilla \"q\" 5.0" 1 "web@docker" "-" 12ms`))
if err != nil || ev.Method != "POST" || ev.Status != 404 || ev.UA != `Mozilla "q" 5.0` || ev.Referer != `https://x/"y` || ev.OriginStatus != 0 {
t.Fatalf("%+v %v", ev, err)
}
for _, bad := range []string{"garbage", `1.2.3.4 - - [bad] "GET / HTTP/1.1" 200 1 "-" "-" 1`, `1.2.3.4 - - [15/Nov/2026:04:10:52 +0000] "GET / HTTP/1.1" 200 1 "-" "-`, `nope - - [15/Nov/2026:04:10:52 +0000] "GET / HTTP/1.1" 200 1 "-" "-" 1`} {
if _, err := ParseTraefik([]byte(bad)); err == nil {
t.Errorf("accepted %q", bad)
}
}
}
+121
View File
@@ -1,10 +1,12 @@
package core
import (
"bytes"
"encoding/json"
"errors"
"net/netip"
"regexp"
"strconv"
"strings"
"time"
)
@@ -72,6 +74,9 @@ type traefikLine struct {
// ParseTraefik parses one Traefik JSON access log line.
func ParseTraefik(line []byte) (Event, error) {
if t := bytes.TrimLeft(line, " \t"); len(t) > 0 && t[0] != '{' {
return parseTraefikText(string(t))
}
var l traefikLine
if err := json.Unmarshal(line, &l); err != nil {
return Event{}, err
@@ -213,3 +218,119 @@ func ParseFail2ban(line string) (Event, error) {
Unban: m[3] == "Unban", Restore: m[3] == "Restore Ban",
}, nil
}
// textFields splits a Traefik text (extended CLF) access log line into its
// fields. Quoted fields may carry backslash escapes, the [time] field is read
// up to the closing bracket.
func textFields(s string) ([]string, bool) {
var out []string
i := 0
for i < len(s) {
switch c := s[i]; {
case c == ' ' || c == '\t':
i++
case c == '"':
var b strings.Builder
i++
closed := false
for i < len(s) {
if s[i] == '\\' && i+1 < len(s) {
b.WriteByte(s[i+1])
i += 2
continue
}
if s[i] == '"' {
closed = true
i++
break
}
b.WriteByte(s[i])
i++
}
if !closed {
return nil, false
}
out = append(out, b.String())
case c == '[':
j := strings.IndexByte(s[i:], ']')
if j < 0 {
return nil, false
}
out = append(out, s[i+1:i+j])
i += j + 1
default:
j := i
for j < len(s) && s[j] != ' ' && s[j] != '\t' {
j++
}
out = append(out, s[i:j])
i = j
}
}
return out, true
}
func dash(s string) string {
if s == "-" {
return ""
}
return s
}
// parseTraefikText parses the default Traefik access log format:
// host ident user [time] "METHOD path PROTO" status size "referer" "ua" count "router" "backend" Nms
// The format carries no Host header, so Domain stays empty.
func parseTraefikText(line string) (Event, error) {
f, ok := textFields(line)
if !ok || len(f) < 9 {
return Event{}, errors.New("not a traefik text line")
}
ip, ok := cleanIP(f[0])
if !ok {
if _, err := netip.ParseAddr(strings.TrimSpace(f[0])); err != nil {
return Event{}, errors.New("bad client address")
}
return Event{}, ErrIgnored
}
t, err := time.Parse("02/Jan/2006:15:04:05 -0700", f[3])
if err != nil {
return Event{}, err
}
rl := strings.Fields(f[4])
if len(rl) < 2 {
return Event{}, errors.New("bad request line")
}
method, path, proto := rl[0], rl[1], ""
if len(rl) >= 3 {
proto = rl[len(rl)-1]
}
status, err := strconv.Atoi(f[5])
if err != nil || status < 100 || status > 999 {
return Event{}, errors.New("bad status")
}
var size int64
if f[6] != "-" {
if size, err = strconv.ParseInt(f[6], 10, 64); err != nil {
return Event{}, err
}
}
ev := Event{
Time: t.UTC(), IP: ip, Source: "traefik", Status: status,
Method: clip(method, 12), Path: clip(path, maxPath), Proto: clip(proto, 12),
Bytes: size, Referer: clip(dash(f[7]), 300), UA: clip(dash(f[8]), maxUA),
}
if len(f) > 10 {
ev.Router = clip(dash(f[10]), 64)
}
if len(f) > 11 && dash(f[11]) != "" {
ev.OriginStatus = status
}
if len(f) > 12 {
if d, err := time.ParseDuration(strings.TrimSpace(f[12])); err == nil {
ev.DurationNS = d.Nanoseconds()
}
}
c := Classify(method, path, status)
ev.Cat, ev.Soft, ev.Strong, ev.Weak = c.Cat, c.Soft, c.Strong, c.Weak
return ev, nil
}
+2 -1
View File
@@ -13,6 +13,7 @@ type integritySource struct {
Lines uint64 `json:"lines"`
Malformed uint64 `json:"malformed"`
Last int64 `json:"last"`
Error string `json:"error,omitempty"`
}
type integrityHost struct {
@@ -97,7 +98,7 @@ func (s *Server) integrity(w http.ResponseWriter, r *http.Request) {
}
continue
}
hh.Sources = append(hh.Sources, integritySource{Name: src.Name, State: src.State, Lines: src.Lines, Malformed: src.Malformed, Last: src.LastEvent})
hh.Sources = append(hh.Sources, integritySource{Name: src.Name, State: src.State, Lines: src.Lines, Malformed: src.Malformed, Last: src.LastEvent, Error: src.Error})
lines += src.Lines
bad += src.Malformed
if src.LastEvent > hh.LastEvent {
+1 -1
View File
@@ -224,7 +224,7 @@
function countryLabel(cc) { return (flag(cc) + ' ' + countryName(cc)).trim(); }
var KNOWN_CATS = ['ok', 'notfound', 'scanner', 'exploit', 'bruteforce', 'ssh-fail', 'ssh-probe', 'ssh-ok', 'ban'];
var KNOWN_STATES = ['following', 'waiting', 'backfill', 'error', 'disabled'];
var KNOWN_STATES = ['following', 'waiting', 'backfill', 'error', 'degraded', 'disabled'];
var KNOWN_LEVELS = ['hostile', 'suspicious', 'low'];
var KNOWN_TONES = ['neutral', 'ok', 'warn', 'danger', 'info'];
var CHART_CATS = ['notfound', 'scanner', 'bruteforce', 'exploit', 'ssh-fail', 'ssh-probe', 'ban'];
+2
View File
@@ -243,6 +243,7 @@ window.URUTAU_I18N = {
'state.waiting': 'waiting for file',
'state.backfill': 'reading history',
'state.error': 'error',
'state.degraded': 'degraded',
'state.disabled': 'disabled',
'cat.ok': 'ok',
'cat.notfound': 'Nonexistent page (404)',
@@ -744,6 +745,7 @@ window.URUTAU_I18N = {
'state.waiting': 'aguardando arquivo',
'state.backfill': 'lendo histórico',
'state.error': 'erro',
'state.degraded': 'degradada',
'state.disabled': 'desativada',
'cat.ok': 'ok',
'cat.notfound': 'Página inexistente (404)',
+6 -4
View File
@@ -5,7 +5,7 @@
(function () {
'use strict';
var STATES = { following: 1, waiting: 1, backfill: 1, error: 1, disabled: 1 };
var STATES = { following: 1, waiting: 1, backfill: 1, error: 1, degraded: 1, disabled: 1 };
var ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 4 6v6c0 4.5 3.2 7.8 8 9 4.8-1.2 8-4.5 8-9V6l-8-3z"/><path d="m9 12 2 2 4-4"/></svg>';
function boot() {
@@ -44,6 +44,7 @@
'ig.state.waiting': 'waiting',
'ig.state.backfill': 'catching up',
'ig.state.error': 'error',
'ig.state.degraded': 'degraded',
'ig.state.disabled': 'disabled',
'ig.peers.title': 'Peers',
'ig.peers.none': 'No peers configured.',
@@ -96,6 +97,7 @@
'ig.state.waiting': 'aguardando',
'ig.state.backfill': 'recuperando',
'ig.state.error': 'erro',
'ig.state.degraded': 'degradada',
'ig.state.disabled': 'desativada',
'ig.peers.title': 'Peers',
'ig.peers.none': 'Nenhum peer configurado.',
@@ -172,7 +174,7 @@
hosts.forEach(function (x) {
gaps += (x.gaps || []).length;
if (x.online) onlineN++;
(x.sources || []).forEach(function (s) { lines += s.lines; bad += s.malformed; if (s.state === 'error') errors++; });
(x.sources || []).forEach(function (s) { lines += s.lines; bad += s.malformed; if (s.state === 'error' || s.state === 'degraded') errors++; });
});
var offline = peers.filter(function (p) { return !p.online; }).length;
var rate = lines + bad > 0 ? bad / (lines + bad) : 0;
@@ -233,8 +235,8 @@
var rows = [];
hosts.forEach(function (x) {
(x.sources || []).forEach(function (s) {
var tone = s.state === 'error' ? 'danger' : s.state === 'following' ? 'ok' : 'neutral';
rows.push([x.name, s.name, U.ui.badge(STATES[s.state] ? t('ig.state.' + s.state) : String(s.state || ''), tone), nf(s.lines), nf(s.malformed), s.last ? U.fmt.ago(s.last) : '-']);
var tone = (s.state === 'error' || s.state === 'degraded') ? 'danger' : s.state === 'following' ? 'ok' : 'neutral';
rows.push([x.name, s.name, U.ui.badge(STATES[s.state] ? t('ig.state.' + s.state) + (s.state === 'degraded' && s.error ? ' (' + s.error + ')' : '') : String(s.state || ''), tone), nf(s.lines), nf(s.malformed), s.last ? U.fmt.ago(s.last) : '-']);
});
});
sp2.body.appendChild(rows.length ? table([t('ig.src.host'), t('ig.src.name'), t('ig.src.state'), t('ig.src.lines'), t('ig.src.bad'), t('ig.src.last')], rows) : U.ui.empty(t('ig.src.none')));
+1 -1
View File
@@ -353,7 +353,7 @@ td small { display: block; color: var(--ink-muted); font-size: .8125rem; overflo
.host dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; margin: 10px 0 0; font-size: .875rem; }
.host dd { text-align: right; font-variant-numeric: tabular-nums; }
.host dt { color: var(--ink-muted); }
.st-following { color: var(--ok); } .st-waiting, .st-backfill { color: var(--warn); } .st-error { color: var(--danger); } .st-disabled { color: var(--ink-muted); }
.st-following { color: var(--ok); } .st-waiting, .st-backfill { color: var(--warn); } .st-error, .st-degraded { color: var(--danger); font-weight: 600; } .st-disabled { color: var(--ink-muted); }
.kv { display: grid; grid-template-columns: minmax(120px, auto) minmax(0, 1fr); gap: 6px var(--s-4); }
.kv dt { color: var(--ink-muted); } .kv dd { overflow-wrap: anywhere; }