@@ -36,6 +36,7 @@ func NewListener(db *database.DB, runtimeConfig *config.RuntimeConfig, logs *log
36
36
l .mux .HandleFunc ("/process-event" , l .ProcessEvent )
37
37
l .mux .HandleFunc ("/dump-config" , l .DumpConfig )
38
38
l .mux .HandleFunc ("/dump-incidents" , l .DumpIncidents )
39
+ l .mux .HandleFunc ("/dump-schedules" , l .DumpSchedules )
39
40
return l
40
41
}
41
42
@@ -220,3 +221,32 @@ func (l *Listener) DumpIncidents(w http.ResponseWriter, r *http.Request) {
220
221
enc .SetIndent ("" , " " )
221
222
_ = enc .Encode (encodedIncidents )
222
223
}
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