Skip to content
Snippets Groups Projects
Verified Commit 09c13409 authored by Ada's avatar Ada
Browse files

:wrench: Make check interval configurable

parent c7b2ffe7
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ disable = [
"noctx",
"exportloopref",
"gochecknoglobals", # Too strict
"godox",
]
[issues]
......
......@@ -11,6 +11,8 @@ db = 0
user = ""
password = ""
[alerting]
interval = 1 # Check interval
[[probe]]
name = "example" # Unique name for probe
......
......@@ -24,6 +24,8 @@ func SendNotification(c config.Alerting, message string) error {
return errDisabledWebhook
}
logrus.Debugf("sending a webhook with message : %s", message)
data, err := json.Marshal(webhook{
Username: c.Username,
Content: message,
......@@ -47,16 +49,17 @@ func SendNotification(c config.Alerting, message string) error {
return nil
}
func InitCheck(targets []config.Target) {
func InitCheck(targets []config.Target, interval int) {
logrus.Debug("initializing alerting")
for {
logrus.Debug("1.1")
err := checkStatus(targets)
if err != nil {
logrus.Error(err)
}
time.Sleep(5 * time.Minute) // TODO make it configurable
time.Sleep(time.Duration(interval) * time.Minute)
}
}
......
......@@ -11,6 +11,7 @@ type Config struct {
Listen string
Probe []Target
Redis cache.Config
Check Check `toml:"alerting"`
}
type Target struct {
......@@ -21,6 +22,10 @@ type Target struct {
Webhooks Alerting
}
type Check struct {
Interval int
}
type Alerting struct {
Enabled bool
Username string
......
......@@ -11,6 +11,9 @@ db = 0
user = "test"
password = "Password123"
[alerting]
interval = 1
[[probe]]
name = "example" # Unique name for probe
description = "Check https://example.org website"
......
......@@ -33,6 +33,7 @@ func TestToml(t *testing.T) {
User: "test",
Password: "Password123",
},
Check: Check{Interval: 1},
Probe: []Target{{
Name: "example",
Description: "Check https://example.org website",
......
......@@ -47,7 +47,7 @@ func main() {
}
}
go alerting.InitCheck(c.Probe)
go alerting.InitCheck(c.Probe, c.Check.Interval)
router.Init(c)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment