Make health check interval configurable

This commit is contained in:
Andrew Ayer 2023-02-06 09:18:37 -05:00
parent 6c798699f8
commit 2a24abaa31
4 changed files with 11 additions and 4 deletions

View File

@ -110,6 +110,7 @@ func main() {
var flags struct {
batchSize int // TODO-4: respect this option
email []string
healthcheck time.Duration
logs string
noSave bool
script string
@ -122,6 +123,7 @@ func main() {
}
flag.IntVar(&flags.batchSize, "batch_size", 1000, "Max number of entries to request per call to get-entries (advanced)")
flag.Func("email", "Email address to contact when matching certificate is discovered (repeatable)", appendFunc(&flags.email))
flag.DurationVar(&flags.healthcheck, "healthcheck", 24*time.Hour, "How frequently to perform a healt check")
flag.StringVar(&flags.logs, "logs", defaultLogList, "File path or URL of JSON list of logs to monitor")
flag.BoolVar(&flags.noSave, "no_save", false, "Do not save a copy of matching certificates in state directory")
flag.StringVar(&flags.script, "script", "", "Program to execute when a matching certificate is discovered")
@ -152,6 +154,7 @@ func main() {
Script: flags.script,
Email: flags.email,
Stdout: flags.stdout,
HealthCheckInterval: flags.healthcheck,
}
if flags.watchlist == "-" {

View File

@ -9,6 +9,10 @@
package monitor
import (
"time"
)
type Config struct {
LogListSource string
StateDir string
@ -19,4 +23,5 @@ type Config struct {
Script string
Email []string
Stdout bool
HealthCheckInterval time.Duration
}

View File

@ -23,7 +23,6 @@ import (
const (
reloadLogListIntervalMin = 30 * time.Minute
reloadLogListIntervalMax = 90 * time.Minute
healthCheckInterval = 24 * time.Hour
)
func randomDuration(min, max time.Duration) time.Duration {
@ -50,7 +49,7 @@ type daemon struct {
}
func (daemon *daemon) healthCheck(ctx context.Context) error {
if time.Since(daemon.logsLoadedAt) >= healthCheckInterval {
if time.Since(daemon.logsLoadedAt) >= daemon.config.HealthCheckInterval {
if err := notify(ctx, daemon.config, &staleLogListEvent{
Source: daemon.config.LogListSource,
LastSuccess: daemon.logsLoadedAt,
@ -135,7 +134,7 @@ func (daemon *daemon) run(ctx context.Context) error {
reloadLogListTicker := time.NewTicker(reloadLogListInterval())
defer reloadLogListTicker.Stop()
healthCheckTicker := time.NewTicker(healthCheckInterval)
healthCheckTicker := time.NewTicker(daemon.config.HealthCheckInterval)
defer healthCheckTicker.Stop()
for ctx.Err() == nil {

View File

@ -35,7 +35,7 @@ func healthCheckLog(ctx context.Context, config *Config, ctlog *loglist.Log) err
return fmt.Errorf("error loading state file: %w", err)
}
if time.Since(state.LastSuccess) < healthCheckInterval {
if time.Since(state.LastSuccess) < config.HealthCheckInterval {
return nil
}