forked from prometheus/blackbox_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
206 lines (178 loc) · 6.05 KB
/
config.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package main
import (
"fmt"
"strings"
"sync"
"time"
"github.com/prometheus/common/config"
)
type Config struct {
Modules map[string]Module `yaml:"modules"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type SafeConfig struct {
sync.RWMutex
C *Config
}
type Module struct {
Prober string `yaml:"prober"`
Timeout time.Duration `yaml:"timeout"`
HTTP HTTPProbe `yaml:"http"`
TCP TCPProbe `yaml:"tcp"`
ICMP ICMPProbe `yaml:"icmp"`
DNS DNSProbe `yaml:"dns"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type HTTPProbe struct {
// Defaults to 2xx.
ValidStatusCodes []int `yaml:"valid_status_codes"`
PreferredIPProtocol string `yaml:"preferred_ip_protocol"`
NoFollowRedirects bool `yaml:"no_follow_redirects"`
FailIfSSL bool `yaml:"fail_if_ssl"`
FailIfNotSSL bool `yaml:"fail_if_not_ssl"`
Method string `yaml:"method"`
Headers map[string]string `yaml:"headers"`
FailIfMatchesRegexp []string `yaml:"fail_if_matches_regexp"`
FailIfNotMatchesRegexp []string `yaml:"fail_if_not_matches_regexp"`
Body string `yaml:"body"`
HTTPClientConfig config.HTTPClientConfig `yaml:"http_client_config,inline"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type QueryResponse struct {
Expect string `yaml:"expect"`
Send string `yaml:"send"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type TCPProbe struct {
PreferredIPProtocol string `yaml:"preferred_ip_protocol"`
QueryResponse []QueryResponse `yaml:"query_response"`
TLS bool `yaml:"tls"`
TLSConfig config.TLSConfig `yaml:"tls_config"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type ICMPProbe struct {
PreferredIPProtocol string `yaml:"preferred_ip_protocol"` // Defaults to "ip6".
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type DNSProbe struct {
PreferredIPProtocol string `yaml:"preferred_ip_protocol"`
TransportProtocol string `yaml:"transport_protocol"`
QueryName string `yaml:"query_name"`
QueryType string `yaml:"query_type"` // Defaults to ANY.
ValidRcodes []string `yaml:"valid_rcodes"` // Defaults to NOERROR.
ValidateAnswer DNSRRValidator `yaml:"validate_answer_rrs"`
ValidateAuthority DNSRRValidator `yaml:"validate_authority_rrs"`
ValidateAdditional DNSRRValidator `yaml:"validate_additional_rrs"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
type DNSRRValidator struct {
FailIfMatchesRegexp []string `yaml:"fail_if_matches_regexp"`
FailIfNotMatchesRegexp []string `yaml:"fail_if_not_matches_regexp"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
func checkOverflow(m map[string]interface{}, ctx string) error {
if len(m) > 0 {
var keys []string
for k := range m {
keys = append(keys, k)
}
return fmt.Errorf("unknown fields in %s: %s", ctx, strings.Join(keys, ", "))
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain Config
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "config"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *Module) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain Module
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "module"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *HTTPProbe) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain HTTPProbe
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "http probe"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *DNSProbe) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain DNSProbe
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "dns probe"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *TCPProbe) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain TCPProbe
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "tcp probe"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *DNSRRValidator) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain DNSRRValidator
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "dns rr validator"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *ICMPProbe) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain ICMPProbe
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "icmp probe"); err != nil {
return err
}
return nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (s *QueryResponse) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain QueryResponse
if err := unmarshal((*plain)(s)); err != nil {
return err
}
if err := checkOverflow(s.XXX, "query response"); err != nil {
return err
}
return nil
}