Skip to content

Commit

Permalink
Add onReady lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
quadseed committed Oct 21, 2023
1 parent da7cd15 commit 93546c9
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}

0 comments on commit 93546c9

Please sign in to comment.