-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprobes.go
90 lines (83 loc) · 1.94 KB
/
probes.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package dashboard
import (
"flag"
"log"
"net"
"sort"
"sync"
"time"
"hkjn.me/prober"
"hkjn.me/probes/dnsprobe"
"hkjn.me/probes/varsprobe"
"hkjn.me/probes/webprobe"
)
// TODO(hkjn): Add support for sending POST requests in webprobe.
var (
proberDisabled = flag.Bool("no_probes", false, "disables probes")
allProbes = prober.Probes{}
createOnce = sync.Once{}
)
// getWebProbes returns the web probes.
func getWebProbes() prober.Probes {
probes := prober.Probes{}
for _, p := range probecfg.WebProbes {
wp := webprobe.NewWithGeneric(
p.Target,
"GET",
p.WantStatus,
[]prober.Option{prober.Interval(time.Minute * 2)},
webprobe.Name(p.Name),
webprobe.InResponse(p.Want))
probes = append(probes, wp)
}
return probes
}
// getVarsProbes returns the vars probes.
func getVarsProbes() prober.Probes {
probes := prober.Probes{}
for _, p := range probecfg.VarsProbes {
probes = append(probes,
varsprobe.New(
p.Target,
varsprobe.Name(p.Name),
varsprobe.Key(p.Key),
varsprobe.WantValue(p.WantValue),
))
}
return probes
}
// getDnsProbes returns the dns probes.
func getDnsProbes() prober.Probes {
probes := prober.Probes{}
for _, p := range probecfg.DnsProbes {
mxRecords := []*net.MX{}
for _, mx := range p.Records.Mx {
mxRecords = append(mxRecords, &net.MX{
Host: mx.Host,
Pref: mx.Pref,
})
}
nsRecords := []*net.NS{}
for _, ns := range p.Records.Ns {
nsRecords = append(nsRecords, &net.NS{Host: ns})
}
p := dnsprobe.New(
p.Target,
dnsprobe.MX(mxRecords),
dnsprobe.A(p.Records.A),
dnsprobe.NS(nsRecords),
dnsprobe.CNAME(p.Records.Cname),
dnsprobe.TXT(p.Records.Txt))
log.Printf("adding dnsprobe: %v\n", p)
probes = append(probes, p)
}
return probes
}
// getProbes returns all probes in the dashboard.
func getProbes() prober.Probes {
createOnce.Do(func() {
allProbes = append(getDnsProbes(), getWebProbes()...)
})
sort.Sort(allProbes)
return allProbes
}