Release / Plan (reuse the published image?) (push) Successful in 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 20s
CI / Tests (Linux, race detector) (push) Successful in 1m10s
Release / ci (push) Successful in 1m10s
Release / Build image (arm64) (push) Successful in 55s
Release / Build image (amd64) (push) Successful in 1m16s
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
New pages grouped in the rail (Monitor, Investigate, Analyze, Operate, Reports): Services (SLO, Apdex, latency app vs proxy), Sessions (stage funnel), Campaigns, Event search, MITRE ATT&CK matrix, Evolution, Concentration (Pareto, Gini), Survival (Kaplan-Meier per attack episode, recidivists), Where errors come from (application vs failed attack vs proxy vs client), Protocols and TLS, Defense (fail2ban, SSH, blocklist), Integrity, and a printable executive report. Chart library (donut, radar, stacked area, bars, heatmap, gauge), glossary with accessible "?" tooltips, self-explanatory category names (nonexistent page 404), page loader through pages.json. Unique visitors fixed: real browsers opening a page, one per IP per day, deduplicated across domains, with non-human clients counted apart. Anonymous legitimate visits on the Live page (?visits=1, no IP). Traefik origin, service, protocol and TLS fields parsed. Paths and Referer paths drop e-mail and token segments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
3.0 KiB
Go
119 lines
3.0 KiB
Go
package store
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
|
|
)
|
|
|
|
// Gap is a stretch of hours with no event at all from a source that usually has some.
|
|
type Gap struct {
|
|
From int64 `json:"from"`
|
|
To int64 `json:"to"`
|
|
}
|
|
|
|
// MinGapHours is the shortest silence reported as a hole.
|
|
const MinGapHours = 2
|
|
|
|
// HourlyFromTimeline folds a timeline (any step up to one hour, or exactly
|
|
// one hour) into events per hour for the hours [fromHour, toHour] (hour numbers,
|
|
// unix/3600). Hours outside the timeline stay zero.
|
|
func HourlyFromTimeline(tl Timeline, fromHour, toHour int64) []uint32 {
|
|
if toHour < fromHour {
|
|
return []uint32{}
|
|
}
|
|
n := int(toHour-fromHour) + 1
|
|
if n > 24*31 {
|
|
n = 24 * 31
|
|
fromHour = toHour - int64(n) + 1
|
|
}
|
|
out := make([]uint32, n)
|
|
if tl.Step <= 0 {
|
|
return out
|
|
}
|
|
for _, vals := range tl.Series {
|
|
for i, v := range vals {
|
|
if v == 0 {
|
|
continue
|
|
}
|
|
h := (tl.Start + int64(i)*tl.Step) / 3600
|
|
if h < fromHour || h > toHour {
|
|
continue
|
|
}
|
|
out[h-fromHour] += v
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// FindGaps lists runs of at least MinGapHours empty hours after the first
|
|
// busy hour, provided the source is a regular one (at least three busy hours).
|
|
// Gaps are returned as unix seconds [from, to).
|
|
func FindGaps(hourly []uint32, fromHour int64) []Gap {
|
|
busy, first := 0, -1
|
|
for i, v := range hourly {
|
|
if v > 0 {
|
|
busy++
|
|
if first < 0 {
|
|
first = i
|
|
}
|
|
}
|
|
}
|
|
gaps := []Gap{}
|
|
if busy < 3 {
|
|
return gaps
|
|
}
|
|
run := -1
|
|
flush := func(end int) {
|
|
if run >= 0 && end-run >= MinGapHours {
|
|
gaps = append(gaps, Gap{From: (fromHour + int64(run)) * 3600, To: (fromHour + int64(end)) * 3600})
|
|
}
|
|
run = -1
|
|
}
|
|
for i := first; i < len(hourly); i++ {
|
|
if hourly[i] == 0 {
|
|
if run < 0 {
|
|
run = i
|
|
}
|
|
} else {
|
|
flush(i)
|
|
}
|
|
}
|
|
flush(len(hourly))
|
|
return gaps
|
|
}
|
|
|
|
// LogStats describes the event log on disk.
|
|
type LogStats struct {
|
|
Enabled bool `json:"enabled"`
|
|
Days int `json:"days"`
|
|
Bytes int64 `json:"bytes"`
|
|
Dropped uint64 `json:"dropped"`
|
|
}
|
|
|
|
// LogStats counts the days with events (scan cached for five minutes), the
|
|
// size on disk and the events dropped by the writer.
|
|
func (s *Store) LogStats() LogStats {
|
|
if s.elog == nil {
|
|
return LogStats{}
|
|
}
|
|
k := studyKey{kind: "integrity-log"}
|
|
d := s.cachedTTL(k, 5*time.Minute, func() any {
|
|
days := map[int64]bool{}
|
|
now := s.now().Unix()
|
|
s.elog.Scan(evlog.Filter{From: now - int64(s.cfg.Retention/time.Second) - 86400, To: now + 86400}, studyBudget, false, func(r evlog.Rec, _ []byte) bool {
|
|
days[r.T/86400] = true
|
|
return true
|
|
})
|
|
return len(days)
|
|
}).(int)
|
|
return LogStats{Enabled: true, Days: d, Bytes: s.elog.Size(), Dropped: s.elog.Dropped()}
|
|
}
|
|
|
|
// GeoBuilds, when set by the application (serve.go: geo.Resolver.Status() ->
|
|
// City.Build / ASN.Build, as `urutau doctor` shows them), returns the build
|
|
// time of the city and ASN databases in unix seconds (0 when unknown). The
|
|
// source list the dashboard receives hides paths, so the server cannot open the
|
|
// geo directory itself.
|
|
var GeoBuilds func() (city, asn int64)
|