probe

package
v0.3.0-rc.53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

View Source
var Probers = []string{"http", "tcp", "registry", "git", "rdap"}

Probers are the kinds of check.

Functions

func CheckSecretFiles

func CheckSecretFiles(ms *Modules) error

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

func SecretName(field, name string) error

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.

func Write

func Write(w io.Writer, r Result) error

Write puts a result in the Prometheus text format.

func WriteSamples

func WriteSamples(w io.Writer, samples []Sample) error

WriteSamples puts samples in the Prometheus text format, a HELP and TYPE line per name.

Types

type Duration

type Duration time.Duration

Duration is a time.Duration written as "20s" in YAML.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads "20s".

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

type Modules struct {
	Modules map[string]*Module `yaml:"modules"`
}

Modules are the named ways to probe a target.

func LoadModules

func LoadModules(path string) (*Modules, error)

LoadModules reads and checks a module file.

func ParseModules

func ParseModules(b []byte) (*Modules, error)

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.

func (*Prober) Run

func (p *Prober) Run(ctx context.Context, m *Module, target string) Result

Run probes target with module m, within the module's timeout and ctx.

func (*Prober) RunExercise

func (p *Prober) RunExercise(ctx context.Context, m *Module, target string, challenge *exercise.Challenge, at time.Time) Result

RunExercise collects an optional receipt from the gateway-designated built-in drill target.

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.

func (*Reloadable) Load

func (r *Reloadable) Load() *Modules

Load returns the current modules.

func (*Reloadable) Store

func (r *Reloadable) Store(m *Modules)

Store sets the modules.

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

type Sample struct {
	Name, Help, Labels, Type string
	Value                    float64
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL