diff --git a/main.go b/main.go index 8500e67..a5342e2 100644 --- a/main.go +++ b/main.go @@ -18,27 +18,18 @@ func main() { client := slack.New(token) - ticker := time.NewTicker(time.Millisecond * 60 * 60 * 1000) + ticker := time.NewTicker(time.Millisecond * 1000 * 60 * 60) defer ticker.Stop() log.Printf("DNS Watchdog task has been started") count := 0 + execLookup(*client, channelId, dnsServer, domain, &count) for { select { case <-ticker.C: log.Printf("count=%d\n", count) - ok := lookupMXRecords(dnsServer, domain) - if ok { - count++ - if count > 24 { - count = 0 - SendDailyNotification(*client, channelId, dnsServer, domain) - } - } else { - count = 0 - SendHourlyNotification(*client, channelId, dnsServer, domain) - } + execLookup(*client, channelId, dnsServer, domain, &count) } } } @@ -61,3 +52,17 @@ func lookupMXRecords(dnsServer string, domain string) bool { } return true } + +func execLookup(client slack.Client, channelId string, dnsServer string, domain string, count *int) { + ok := lookupMXRecords(dnsServer, domain) + if ok { + *count++ + if *count > 24 { + *count = 0 + SendDailyNotification(client, channelId, dnsServer, domain) + } + } else { + *count = 0 + SendHourlyNotification(client, channelId, dnsServer, domain) + } +}