-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
66 lines (62 loc) · 1.42 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"log"
"time"
"csz.net/mata/conf"
"csz.net/mata/utils"
)
var Once bool
func main() {
for {
for _, mata := range conf.Config.Mata {
log.Println("开始检测" + mata.Target)
send := false
msg := "服务器在线"
onlineCount := 0
online := false
for i := 0; i < 3; i++ {
if utils.Check(mata.Target, 5*time.Second) {
onlineCount++
}
time.Sleep(10 * time.Second)
}
if onlineCount >= 2 {
online = true
}
if online {
log.Println(msg)
ok, dns := utils.GetDnsRecoid(mata.Main.Name, mata.Main.ZoneID)
if ok && dns.Content != mata.Main.Content {
send = true
log.Printf("修改解析【%s】\n", mata.Main.Name)
utils.Dns(mata.Main, dns.ID, mata.Main.ZoneID)
}
} else {
msg = "服务器离线"
log.Println(msg)
ok, dns := utils.GetDnsRecoid(mata.Then.Name, mata.Then.ZoneID)
if ok && dns.Content != mata.Then.Content {
send = true
log.Printf("修改解析【%s】\n", mata.Then.Name)
utils.Dns(mata.Then, dns.ID, mata.Then.ZoneID)
}
}
if send && conf.Config.BotToken != "" && conf.Config.ChatID != "" {
msg = "【" + mata.Target + "】" + msg
go utils.SendMessage("#MATA " + msg)
}
}
if Once {
return
}
time.Sleep(time.Duration(conf.Config.Corn) * time.Second)
}
}
func init() {
once := flag.Bool("once", false, "Run once")
flag.Parse()
if *once {
Once = true
}
}