foreman

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserAgent = fmt.Sprintf("foreman_exporter/%s", version.Version)
)

Functions

func SortedFactNames added in v1.4.0

func SortedFactNames(names []string) []string

SortedFactNames is only used to keep the search stable across runs, which makes the queries comparable in foreman's own logs.

Types

type BatchFactsResult added in v1.4.0

type BatchFactsResult struct {
	HostIDs []int64
	Facts   map[string]map[string]string
	// Missing lists the hosts the batch asked for that came back with no fact at
	// all. Knowing the ids that were requested is the whole point of batching by
	// host: without it, a host absent from the response is indistinguishable
	// from a host that simply has nothing matching the search.
	Missing   []string
	Pages     int
	Truncated bool
	Err       error
}

BatchFactsResult is what one batch of host ids brought back. Facts holds the raw, unfiltered facts keyed by hostname; HostIDs is what the batch asked for, which is what lets the caller tell "this host has no matching fact" apart from "this host was lost".

type ClientConfig added in v1.3.0

type ClientConfig struct {
	BaseURL       *url.URL
	Username      string
	Password      string
	SkipTLSVerify bool

	// Concurrency caps the in-flight requests fanned out per collector.
	Concurrency int64
	// MaxConnsPerHost sizes the idle connection pool. 0 derives it from
	// Concurrency. It is not a hard cap on open connections: both collectors can
	// fan out at the same time, so capping would make them queue on the
	// transport instead of on their own semaphore.
	MaxConnsPerHost int64
	Limit           int64
	RetryMax        int64
	// RetryMaxWait caps the Retry-After delay honored on 429/503 (0 = no cap).
	RetryMaxWait time.Duration
	// RateLimit paces outgoing requests, in requests per second (0 = disabled).
	// It bounds throughput, where Concurrency bounds parallelism: the two are
	// independent, and which one binds depends on how fast foreman answers.
	RateLimit float64
	// RateLimitBurst is the token bucket depth. 0 derives it from RateLimit.
	RateLimitBurst int64

	Search               string
	SearchHostFact       string
	IncludeHostFactRegex *regexp.Regexp
	ExcludeHostFactRegex *regexp.Regexp

	// BulkFacts switches the host fact collection to /api/v2/fact_values, one
	// request per batch of host ids. FactNames, when set, pushes the fact-name
	// selection to the server instead of downloading everything and filtering
	// it away client-side.
	BulkFacts      bool
	FactBatchSize  int64
	FactPerPage    int64
	FactMaxPages   int64
	FactNames      []string
	FactInOperator string
	MaxURLLength   int
	// HostListPerPage sizes the thin host list pages the fact collector walks
	// before collecting anything. 0 uses the built-in default.
	HostListPerPage int64

	Log *logrus.Logger
}

ClientConfig holds the foreman HTTP client settings. It replaces the long positional argument list NewHTTPClient used to take, so adding a knob no longer risks silently swapping two same-typed arguments at a call site.

type ErrorResult added in v0.0.6

type ErrorResult struct {
	Status int64  `json:"status"`
	Error  string `json:"error"`
}

type HTTPClient

type HTTPClient struct {
	BaseURL  *url.URL
	Username string
	Password string

	Concurrency          int64
	Limit                int64
	Search               string
	SearchHostFact       string
	IncludeHostFactRegex *regexp.Regexp
	ExcludeHostFactRegex *regexp.Regexp
	Log                  *logrus.Logger

	// BulkFacts collects facts through /api/v2/fact_values by batch of host ids
	// instead of one request per host.
	BulkFacts       bool
	FactBatchSize   int64
	FactPerPage     int64
	FactMaxPages    int64
	FactNames       []string
	FactInOperator  string
	MaxURLLength    int
	HostListPerPage int64
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(cfg ClientConfig) *HTTPClient

func (*HTTPClient) DoWithContext

func (c *HTTPClient) DoWithContext(ctx context.Context, r *http.Request, data interface{}) error

DoWithContext sends an API Request and returns back the response. The API response is checked to see if it was a successful call. A successful call is then checked to see if we need to unmarshal since some resources have their own implements of unmarshal.

func (*HTTPClient) GetFactValues added in v1.4.0

func (c *HTTPClient) GetFactValues(ctx context.Context, search string, page, perPage int64) (HostFactsResponse, error)

GetFactValues fetches one page of /api/v2/fact_values.

func (*HTTPClient) GetFactValuesBatch added in v1.4.0

func (c *HTTPClient) GetFactValuesBatch(ctx context.Context, hosts []Host) BatchFactsResult

GetFactValuesBatch fetches every fact of the given hosts in one request, following pages when the response fills one.

func (*HTTPClient) GetHostFacts

func (c *HTTPClient) GetHostFacts(ctx context.Context, hostID, page, perPage int64) (HostFactsResponse, error)

func (*HTTPClient) GetHostFactsWithConcurrency

func (c *HTTPClient) GetHostFactsWithConcurrency(hosts []Host) []HostFactsWithConcurrencyResult

GetHostFactsWithConcurrency sends requests in parallel but only up to a certain limit, and furthermore it's only parallel up to the amount of CPUs but is always concurrent up to the concurrency limit

func (*HTTPClient) GetHostWithConcurrency

func (c *HTTPClient) GetHostWithConcurrency(thin string, pages []int64, perPage int64) []HostWithConcurrencyResult

GetHostWithConcurrency sends requests in parallel but only up to a certain limit, and furthermore it's only parallel up to the amount of CPUs but is always concurrent up to the concurrency limit

func (*HTTPClient) GetHosts

func (c *HTTPClient) GetHosts(ctx context.Context, thin string, page, perPage int64) (HostResponse, error)

func (*HTTPClient) GetHostsFactsFiltered

func (c *HTTPClient) GetHostsFactsFiltered() (map[string]map[string]string, error)

func (*HTTPClient) GetHostsFiltered

func (c *HTTPClient) GetHostsFiltered(perPage int64) ([]Host, error)

func (*HTTPClient) OnRequestCompleted

func (c *HTTPClient) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the API request completion callback

func (*HTTPClient) SetHostsFactsRegistry added in v0.0.6

func (c *HTTPClient) SetHostsFactsRegistry(reg prometheus.Registerer)

Set hosts facts prometheus registry

func (*HTTPClient) SetHostsRegistry added in v0.0.6

func (c *HTTPClient) SetHostsRegistry(reg prometheus.Registerer)

Set hosts prometheus registry

type Host

type Host struct {
	ID                       int64  `json:"id"`
	Name                     string `json:"name"`
	GlobalStatusLabel        string `json:"global_status_label,omitempty"`
	ConfigurationStatusLabel string `json:"configuration_status_label,omitempty"`
	BuildStatusLabel         string `json:"build_status_label,omitempty"`
	OrganizationName         string `json:"organization_name,omitempty"`
	EnvironmentName          string `json:"environment_name,omitempty"`
	OperatingSystemName      string `json:"operatingsystem_name,omitempty"`
	OwnerName                string `json:"owner_name,omitempty"`
	LocationName             string `json:"location_name,omitempty"`
	ModelName                string `json:"model_name,omitempty"`
	HostgroupName            string `json:"hostgroup_name,omitempty"`
}

type HostFactsResponse

type HostFactsResponse struct {
	Total   int64                        `json:"total"`
	Page    int64                        `json:"page"`
	PerPage int64                        `json:"per_page"`
	Results map[string]map[string]string `json:"results"`
}

type HostFactsWithConcurrencyResult

type HostFactsWithConcurrencyResult struct {
	Index  int
	Result HostFactsResponse
	Error  error
}

a struct to hold the result from each request including an index which will be used for sorting the results after they come in

type HostResponse

type HostResponse struct {
	Total int64 `json:"total"`
	// Subtotal is how many records match the search. Foreman sets it equal to
	// Total when no search is given; Total itself always counts every record,
	// so paginating on Total overshoots as soon as a search filter is set. It is
	// a pointer so that a search matching nothing (subtotal 0) is not mistaken
	// for a foreman version that does not report the field at all.
	Subtotal *int64 `json:"subtotal"`
	Page     int64  `json:"page"`
	PerPage  int64  `json:"per_page"`
	Results  []Host `json:"results"`
}

type HostWithConcurrencyResult

type HostWithConcurrencyResult struct {
	Index  int
	Result HostResponse
	Error  error
}

a struct to hold the result from each request including an index which will be used for sorting the results after they come in

type LeveledLogrus

type LeveledLogrus struct {
	*logrus.Logger
}

func (*LeveledLogrus) Debug

func (l *LeveledLogrus) Debug(msg string, keysAndValues ...interface{})

func (*LeveledLogrus) Error

func (l *LeveledLogrus) Error(msg string, keysAndValues ...interface{})

func (*LeveledLogrus) Info

func (l *LeveledLogrus) Info(msg string, keysAndValues ...interface{})

func (*LeveledLogrus) Warn

func (l *LeveledLogrus) Warn(msg string, keysAndValues ...interface{})

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

Jump to

Keyboard shortcuts

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