Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Add flag to configure reporting delay
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Sep 20, 2023
1 parent 997bf67 commit a687b6a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cmds/observation-hub/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,28 @@ var (
reportAllChanges bool

errNoChanges = errors.New("no changes")

reportingDelayFlag string
reportingDelay = 10 * time.Minute
)

func init() {
observerModule = modules.Register("observer", nil, startObserver, nil, "captain", "apprise")
observerModule = modules.Register("observer", prepObserver, startObserver, nil, "captain", "apprise")

flag.BoolVar(&reportAllChanges, "report-all-changes", false, "report all changes, no just interesting ones")
flag.StringVar(&reportingDelayFlag, "reporting-delay", "10m", "delay reports to summarize changes")
}

func prepObserver() error {
if reportingDelayFlag != "" {
duration, err := time.ParseDuration(reportingDelayFlag)
if err != nil {
return fmt.Errorf("failed to parse reporting-delay: %w", err)
}
reportingDelay = duration
}

return nil
}

func startObserver() error {
Expand Down Expand Up @@ -212,8 +228,8 @@ query:
switch {
case observedPin.lastUpdateReported:
// Change already reported.
case time.Since(observedPin.lastUpdate) < time.Minute:
// Only report changes if older than one minute.
case time.Since(observedPin.lastUpdate) < reportingDelay:
// Only report changes if older than the configured delay.
default:
// Format and report.
title, changes, err := formatPinChanges(observedPin.previous, observedPin.latest)
Expand Down Expand Up @@ -258,6 +274,7 @@ var (
"HopDistance",
"Info.entryPolicy", // Alternatively, ignore "Info.Entry"
"Info.exitPolicy", // Alternatively, ignore "Info.Exit"
"Info.parsedTransports",
"Info.Timestamp",
"SessionActive",
"Status.Keys",
Expand Down

0 comments on commit a687b6a

Please sign in to comment.