UpdatedTimeZone
All checks were successful
release-tag / release-image (push) Successful in 2m13s

This commit is contained in:
2026-04-25 22:14:43 +02:00
parent c563367978
commit d1418e390a

20
main.go
View File

@@ -864,6 +864,8 @@ type Config struct {
BaselineMediumZScore float64
BaselineHighZScore float64
BaselineSuppressFor time.Duration
Timezone string
}
type LogPayload struct {
@@ -934,6 +936,8 @@ type server struct {
detector *detector
startTime time.Time
templates *template.Template
location *time.Location
}
type detector struct {
@@ -1161,6 +1165,11 @@ var (
func main() {
cfg := loadConfig()
logger := log.New(os.Stdout, "", log.LstdFlags|log.Lmicroseconds|log.LUTC)
loc, err := time.LoadLocation(cfg.Timezone)
if err != nil {
logger.Printf("invalid TZ %q, falling back to Local: %v", cfg.Timezone, err)
loc = time.Local
}
db, err := sql.Open("mysql", cfg.DBDSN)
if err != nil {
@@ -1271,6 +1280,7 @@ func main() {
registry: reg,
detector: d,
startTime: time.Now().UTC(),
location: loc,
}
tmpl := template.Must(template.New("ui").Funcs(template.FuncMap{
@@ -1279,7 +1289,7 @@ func main() {
if t.IsZero() {
return ""
}
return t.Local().Format("2006-01-02 15:04:05")
return t.In(loc).Format("2006-01-02 15:04:05 MST")
},
"short": func(s string, n int) string {
if len(s) <= n {
@@ -2481,6 +2491,8 @@ func loadConfig() Config {
BaselineMediumZScore: getenvFloat("BASELINE_MEDIUM_Z", 2.5),
BaselineHighZScore: getenvFloat("BASELINE_HIGH_Z", 4.0),
BaselineSuppressFor: getenvDuration("BASELINE_SUPPRESS_FOR", 1*time.Hour),
Timezone: getenv("TZ", "Europe/Berlin"),
}
}
@@ -2700,7 +2712,7 @@ LIMIT 1
const upd = `
UPDATE agents
SET last_seen = CURRENT_TIMESTAMP(6), last_ip = ?
SET last_seen = UTC_TIMESTAMP(6), last_ip = ?
WHERE id = ?
`
if _, err := s.db.ExecContext(ctx, upd, remoteIP, id); err != nil {
@@ -2726,7 +2738,7 @@ func (s *server) enrollNewAgent(ctx context.Context, hostname, apiKey, remoteIP
const ins = `
INSERT INTO agents (hostname, api_key_hash, first_seen, last_seen, last_ip, is_enabled)
VALUES (?, ?, CURRENT_TIMESTAMP(6), CURRENT_TIMESTAMP(6), ?, 1)
VALUES (?, ?, UTC_TIMESTAMP(6), UTC_TIMESTAMP(6), ?, 1)
`
res, err := tx.ExecContext(ctx, ins, hostname, sha256Hex(apiKey), remoteIP)
if err != nil {
@@ -3070,7 +3082,7 @@ SET avg_count = ?,
m2_count = ?,
stddev_count = ?,
sample_count = ?,
last_updated = CURRENT_TIMESTAMP(6)
last_updated = UTC_TIMESTAMP(6)
WHERE hostname = ?
AND channel_name = ?
AND event_id = ?