-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigRemoteUpdate.go
50 lines (42 loc) · 1.04 KB
/
configRemoteUpdate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"math/rand"
log "github.com/sirupsen/logrus"
)
func updateConfigCron() string {
minute := rand.Intn(60) //nolint:mnd,gosec // Only used to distribute load
return fmt.Sprintf("0 %d * * * *", minute)
}
func updateConfigFromRemote() {
log.Debug("starting remote rule update")
err := patchConfig(
cfg.Config,
"Remote Update", "[email protected]",
"update rules from subscription URLs",
func(cfg *configFile) error {
var updates int
for _, r := range cfg.Rules {
logger := log.WithField("rule", r.MatcherID())
rhu, err := r.UpdateFromSubscription(context.Background())
if err != nil {
logger.WithError(err).Error("updating rule")
continue
}
if rhu {
updates++
logger.Info("updated rule from remote URL")
}
}
log.WithField("updates", updates).Debug("remote rule update finished")
if updates == 0 {
return errSaveNotRequired
}
return nil
},
)
if err != nil {
log.WithError(err).Error("updating config rules from subscriptions")
}
}