diff options
| author | Fuwn <[email protected]> | 2026-01-20 17:16:22 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 17:16:22 -0800 |
| commit | 2371b28128213fbcc8d1c062dccc3074e6b0fa98 (patch) | |
| tree | 84452dbf5f2b1821d1fc5cf8ecdb0a5ad2b74f56 /internal/monitor/http.go | |
| parent | fix: Use wildcard path for badge endpoint to support .svg extension (diff) | |
| download | kaze-2371b28128213fbcc8d1c062dccc3074e6b0fa98.tar.xz kaze-2371b28128213fbcc8d1c062dccc3074e6b0fa98.zip | |
feat: Use composite group/name key for monitor identification
Previously monitors were identified by just their name, causing monitors
with the same name in different groups to share data in the database.
Changes:
- Add ID() method to MonitorConfig returning 'group/name' format
- Add Group field to MonitorConfig (set at runtime)
- Update Monitor interface with ID() and Group() methods
- Update all monitor implementations (http, tcp, dns, icmp, gemini,
graphql, database) to use composite ID
- Update Scheduler to use monitor ID instead of name
- Update server handlers to use composite ID for stats lookups
- Change API routes to use {group}/{name} pattern:
- /api/monitor/{group}/{name}
- /api/history/{group}/{name}
- /api/uptime/{group}/{name}
- /api/badge/{group}/{name}.svg
- URL-encode group and name components to handle special characters
(e.g., slashes in names become %2F)
- Update config.UpdateResetFlag to accept group and name separately
BREAKING: API endpoints now require group in the path. Existing database
data using just monitor names won't be associated with the new composite
keys.
Diffstat (limited to 'internal/monitor/http.go')
| -rw-r--r-- | internal/monitor/http.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/internal/monitor/http.go b/internal/monitor/http.go index ddf8641..cdd7226 100644 --- a/internal/monitor/http.go +++ b/internal/monitor/http.go @@ -15,7 +15,9 @@ import ( // HTTPMonitor monitors HTTP and HTTPS endpoints type HTTPMonitor struct { + id string // unique identifier (group/name) name string + group string monitorType string target string interval time.Duration @@ -82,7 +84,9 @@ func NewHTTPMonitor(cfg config.MonitorConfig) (*HTTPMonitor, error) { } return &HTTPMonitor{ + id: cfg.ID(), name: cfg.Name, + group: cfg.Group, monitorType: cfg.Type, target: target, interval: cfg.Interval.Duration, @@ -102,11 +106,21 @@ func NewHTTPMonitor(cfg config.MonitorConfig) (*HTTPMonitor, error) { }, nil } +// ID returns the unique identifier for this monitor +func (m *HTTPMonitor) ID() string { + return m.id +} + // Name returns the monitor's name func (m *HTTPMonitor) Name() string { return m.name } +// Group returns the group this monitor belongs to +func (m *HTTPMonitor) Group() string { + return m.group +} + // Type returns the monitor type func (m *HTTPMonitor) Type() string { return m.monitorType @@ -145,7 +159,7 @@ func (m *HTTPMonitor) RoundUptime() bool { // Check performs the HTTP/HTTPS check func (m *HTTPMonitor) Check(ctx context.Context) *Result { result := &Result{ - MonitorName: m.name, + MonitorName: m.id, Timestamp: time.Now(), } |