Skip to content

Commit 0b51dec

Browse files
committed
Add /dump-schedules debug endpoint
This allows to quickly dump all schedules and how they expand to contacts for the next two days for debugging/testing purposes.
1 parent 83678ae commit 0b51dec

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

internal/listener/listener.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewListener(db *database.DB, runtimeConfig *config.RuntimeConfig, logs *log
3636
l.mux.HandleFunc("/process-event", l.ProcessEvent)
3737
l.mux.HandleFunc("/dump-config", l.DumpConfig)
3838
l.mux.HandleFunc("/dump-incidents", l.DumpIncidents)
39+
l.mux.HandleFunc("/dump-schedules", l.DumpSchedules)
3940
return l
4041
}
4142

@@ -220,3 +221,32 @@ func (l *Listener) DumpIncidents(w http.ResponseWriter, r *http.Request) {
220221
enc.SetIndent("", " ")
221222
_ = enc.Encode(encodedIncidents)
222223
}
224+
225+
func (l *Listener) DumpSchedules(w http.ResponseWriter, r *http.Request) {
226+
if r.Method != http.MethodGet {
227+
w.WriteHeader(http.StatusMethodNotAllowed)
228+
_, _ = fmt.Fprintln(w, "GET required")
229+
return
230+
}
231+
232+
if !l.checkDebugPassword(w, r) {
233+
return
234+
}
235+
236+
l.runtimeConfig.RLock()
237+
defer l.runtimeConfig.RUnlock()
238+
239+
for _, schedule := range l.runtimeConfig.Schedules {
240+
fmt.Fprintf(w, "[id=%d] %q:\n", schedule.ID, schedule.Name)
241+
242+
// Iterate in 30 minute steps as this is the granularity Icinga Notifications Web allows in the configuration.
243+
// Truncation to seconds happens only for a more readable output.
244+
step := 30 * time.Minute
245+
start := time.Now().Truncate(time.Second).Add(step)
246+
for t := start; t.Before(start.Add(48 * time.Hour)); t = t.Add(step) {
247+
fmt.Fprintf(w, "\t%v: %v\n", t, schedule.GetContactsAt(t))
248+
}
249+
250+
fmt.Fprintln(w)
251+
}
252+
}

0 commit comments

Comments
 (0)