-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (47 loc) · 1.07 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
package main
import (
"log"
"os"
"strings"
"github.com/russellcardullo/go-pingdom/pingdom"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
client, err := pingdom.NewClientWithConfig(pingdom.ClientConfig{
APIToken: os.Getenv("PINGDOM_API_TOKEN"),
})
check(err)
checksList, err := client.Checks.List()
check(err)
log.Println(len(checksList), "Total checks")
unique := make([]string, 0)
dup := make(map[int]string)
check:
for _, c := range checksList {
for _, j := range unique {
if c.Name == j {
dup[c.ID] = c.Name
continue check
}
}
unique = append(unique, c.Name)
}
if len(dup) > 0 {
log.Printf("Found %v duplicated checks: %v\n", len(dup), dup)
}
log.Println(len(unique), "Unique checks")
removeDups := os.Getenv("REMOVE_DUPLICATED")
if strings.ToLower(removeDups) == "true" {
log.Println("Start to remove duplicated checks:")
for id, name := range dup {
log.Printf("Removing %v with ID: %v\n", name, id)
removeCheck, err := client.Checks.Delete(id)
check(err)
log.Println(removeCheck)
}
}
}