Documentation
¶
Overview ¶
Package probe checks targets from a probe location, the way the Prometheus Blackbox Exporter does and with the same metric names (probe_success, probe_duration_seconds, probe_http_status_code, probe_ssl_earliest_cert_expiry), so that alert rules work with either. It adds what a status service needs: every failure says why (probe_failure_info{reason}), and multi-step checks for a container registry (token, then manifest), a Git repository over HTTP and a domain's expiry (RDAP).
The module file is the Blackbox Exporter's format for the http and tcp probers (the subset this package implements; anything else is an error rather than silently ignored), plus the registry, git and rdap probers.
Index ¶
- Constants
- Variables
- func CheckSecretFiles(ms *Modules) error
- func Handler(p *Prober, modules func() *Modules, log func(module, target string, r Result)) http.Handler
- func SecretName(field, name string) error
- func Write(w io.Writer, r Result) error
- func WriteSamples(w io.Writer, samples []Sample) error
- type Duration
- type GitModule
- type HTTPModule
- type IPConfig
- type Module
- type Modules
- type Prober
- type QueryResponse
- type RDAPModule
- type RegistryModule
- type Reloadable
- type Result
- type Sample
- type TCPModule
Constants ¶
const ( ReasonDNS = "dns" // the name did not resolve ReasonConnect = "connect" // the connection was refused or reset ReasonTimeout = "timeout" // no answer in time ReasonTLS = "tls" // the TLS handshake or the certificate failed ReasonNotSSL = "not_ssl" // plain HTTP where HTTPS was required ReasonHTTPStatus = "http_status" // an unexpected status code ReasonBody = "body" // the body did not match ReasonBanner = "banner" // a TCP server did not say what was expected ReasonProtocol = "protocol" // an answer of the wrong kind (content type, JSON) ReasonAuth = "auth" // a registry token could not be obtained ReasonManifest = "manifest" // the registry has no such manifest ReasonConfig = "config" // the module or target is wrong )
Failure reasons, the reason label of probe_failure_info.
const DefaultSecretsDir = "/etc/beacon-probe/secrets" //nolint:gosec // G101: a directory, not a credential
DefaultSecretsDir is where a probe looks for the files its modules name.
Variables ¶
var Probers = []string{"http", "tcp", "registry", "git", "rdap"}
Probers are the kinds of check.
Functions ¶
func CheckSecretFiles ¶
CheckSecretFiles checks every module's file fields with SecretName. The centre refuses a module file that fails it. A probe still parses such a file (an older gateway may hand one out) and refuses each probe that would read the file, so that the other modules keep working.
func Handler ¶
func Handler(p *Prober, modules func() *Modules, log func(module, target string, r Result)) http.Handler
Handler serves /probe?module=…&target=…, like the Blackbox Exporter. modules is read on every request, so a reload takes effect. A scrape's own timeout (X-Prometheus-Scrape-Timeout-Seconds) shortens the module's, leaving half a second to answer.
func SecretName ¶
SecretName checks the value of a module's file field: a file name to be found in the secrets directory, without a path. field names the field, for the error; an empty name is no file.
Types ¶
type GitModule ¶
type GitModule struct {
IPConfig `yaml:",inline"`
Username string `yaml:"username"`
PasswordFile string `yaml:"password_file"`
}
GitModule asks a repository for its refs over smart HTTP (what git clone does first). The target is the repository URL.
type HTTPModule ¶
type HTTPModule struct {
IPConfig `yaml:",inline"`
Method string `yaml:"method"`
ValidStatusCodes []int `yaml:"valid_status_codes"`
FollowRedirects *bool `yaml:"follow_redirects"`
FailIfNotSSL bool `yaml:"fail_if_not_ssl"`
FailIfBodyNotMatchesRegexp []string `yaml:"fail_if_body_not_matches_regexp"`
Headers map[string]string `yaml:"headers"`
// contains filtered or unexported fields
}
HTTPModule is an HTTP request and what its answer must look like. Without valid_status_codes any 2xx is success.
type IPConfig ¶
type IPConfig struct {
PreferredIPProtocol string `yaml:"preferred_ip_protocol"`
IPProtocolFallback *bool `yaml:"ip_protocol_fallback"`
}
IPConfig chooses the address family: ip4 or ip6 (default ip6, as in the Blackbox Exporter), with or without falling back to the other one.
type Module ¶
type Module struct {
Prober string `yaml:"prober"`
Timeout Duration `yaml:"timeout"`
HTTP HTTPModule `yaml:"http"`
TCP TCPModule `yaml:"tcp"`
Registry RegistryModule `yaml:"registry"`
Git GitModule `yaml:"git"`
RDAP RDAPModule `yaml:"rdap"`
}
Module is one way to probe a target.
type Modules ¶
Modules are the named ways to probe a target.
func LoadModules ¶
LoadModules reads and checks a module file.
func ParseModules ¶
ParseModules is LoadModules without the file.
type Prober ¶
type Prober struct {
RootCAs *x509.CertPool
Resolver *net.Resolver
UserAgent string
SecretsDir string
}
Prober runs probes. RootCAs is nil for the system's roots and Resolver nil for the system's resolver (tests set their own). SecretsDir is the one directory the files modules name (password_file) are read from (secrets.go); empty for DefaultSecretsDir.
type QueryResponse ¶
type QueryResponse struct {
Expect string `yaml:"expect"`
Send string `yaml:"send"`
// contains filtered or unexported fields
}
QueryResponse sends a line, or waits for a line matching Expect.
type RDAPModule ¶
type RDAPModule struct {
IPConfig `yaml:",inline"`
Server string `yaml:"server"` // default https://rdap.org, which redirects to the registry's server
}
RDAPModule looks up a domain's expiry. The target is the domain.
type RegistryModule ¶
type RegistryModule struct {
IPConfig `yaml:",inline"`
Repository string `yaml:"repository"` // such as library/busybox
Reference string `yaml:"reference"` // a tag or digest; default latest
Username string `yaml:"username"`
PasswordFile string `yaml:"password_file"`
}
RegistryModule pulls a manifest the way a container client does: /v2/, then a token from the realm the registry names (anonymously, or with the credentials), then HEAD the manifest. Nothing is downloaded. The target is the registry's base URL.
type Reloadable ¶
type Reloadable struct {
// contains filtered or unexported fields
}
Reloadable holds the module file and swaps it on reload.
type Result ¶
type Result struct {
Success bool
Reason string // why it failed
Detail string // the error, for the log; never in metrics (it may hold anything a server said)
Duration time.Duration
Samples []Sample
ExerciseReceipt string `json:"-"`
}
Result is what a probe found.
type Sample ¶
Sample is one line of the result: name{labels} value. Type is gauge unless set (counter).
type TCPModule ¶
type TCPModule struct {
IPConfig `yaml:",inline"`
TLS bool `yaml:"tls"`
QueryResponse []QueryResponse `yaml:"query_response"`
}
TCPModule connects, optionally over TLS, and checks what the server says.