Make health check interval configurable
This commit is contained in:
parent
6c798699f8
commit
2a24abaa31
|
@ -110,6 +110,7 @@ func main() {
|
||||||
var flags struct {
|
var flags struct {
|
||||||
batchSize int // TODO-4: respect this option
|
batchSize int // TODO-4: respect this option
|
||||||
email []string
|
email []string
|
||||||
|
healthcheck time.Duration
|
||||||
logs string
|
logs string
|
||||||
noSave bool
|
noSave bool
|
||||||
script string
|
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.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.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.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.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")
|
flag.StringVar(&flags.script, "script", "", "Program to execute when a matching certificate is discovered")
|
||||||
|
@ -152,6 +154,7 @@ func main() {
|
||||||
Script: flags.script,
|
Script: flags.script,
|
||||||
Email: flags.email,
|
Email: flags.email,
|
||||||
Stdout: flags.stdout,
|
Stdout: flags.stdout,
|
||||||
|
HealthCheckInterval: flags.healthcheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.watchlist == "-" {
|
if flags.watchlist == "-" {
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
|
|
||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
LogListSource string
|
LogListSource string
|
||||||
StateDir string
|
StateDir string
|
||||||
|
@ -19,4 +23,5 @@ type Config struct {
|
||||||
Script string
|
Script string
|
||||||
Email []string
|
Email []string
|
||||||
Stdout bool
|
Stdout bool
|
||||||
|
HealthCheckInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
const (
|
const (
|
||||||
reloadLogListIntervalMin = 30 * time.Minute
|
reloadLogListIntervalMin = 30 * time.Minute
|
||||||
reloadLogListIntervalMax = 90 * time.Minute
|
reloadLogListIntervalMax = 90 * time.Minute
|
||||||
healthCheckInterval = 24 * time.Hour
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func randomDuration(min, max time.Duration) time.Duration {
|
func randomDuration(min, max time.Duration) time.Duration {
|
||||||
|
@ -50,7 +49,7 @@ type daemon struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *daemon) healthCheck(ctx context.Context) error {
|
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{
|
if err := notify(ctx, daemon.config, &staleLogListEvent{
|
||||||
Source: daemon.config.LogListSource,
|
Source: daemon.config.LogListSource,
|
||||||
LastSuccess: daemon.logsLoadedAt,
|
LastSuccess: daemon.logsLoadedAt,
|
||||||
|
@ -135,7 +134,7 @@ func (daemon *daemon) run(ctx context.Context) error {
|
||||||
reloadLogListTicker := time.NewTicker(reloadLogListInterval())
|
reloadLogListTicker := time.NewTicker(reloadLogListInterval())
|
||||||
defer reloadLogListTicker.Stop()
|
defer reloadLogListTicker.Stop()
|
||||||
|
|
||||||
healthCheckTicker := time.NewTicker(healthCheckInterval)
|
healthCheckTicker := time.NewTicker(daemon.config.HealthCheckInterval)
|
||||||
defer healthCheckTicker.Stop()
|
defer healthCheckTicker.Stop()
|
||||||
|
|
||||||
for ctx.Err() == nil {
|
for ctx.Err() == nil {
|
||||||
|
|
|
@ -35,7 +35,7 @@ func healthCheckLog(ctx context.Context, config *Config, ctlog *loglist.Log) err
|
||||||
return fmt.Errorf("error loading state file: %w", 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue