Documentation
¶
Index ¶
- Constants
- func BoolPtr(b bool) *bool
- func CollectionNote(detail string) string
- func CommName(name string) string
- func EnvLocaleC() []string
- func FileExistsRegular(path string) bool
- func HostIsContainerized() *bool
- func IntPtr(n int) *int
- func ProcessIsRunning(ctx context.Context, name string) bool
- func ProcessRunningState(ctx context.Context, processes []string) string
- func QueryDistroPackageVersion(packageNames []string) string
- func ReadFileBounded(path string, maxBytes int64) ([]byte, error)
- func ScanContextError(ctx context.Context) error
- func ServiceStateFromList(services []payload.ServiceEntry, want []string) string
- func StringPtr(s string) *string
- func TruncateRunes(s string, max int) string
- func UnitBaseName(name string) string
Constants ¶
const DefaultConfigFileReadLimit int64 = 96 << 10
DefaultConfigFileReadLimit caps typical config file reads (web server snippets, logrotate, cron, etc.).
Variables ¶
This section is empty.
Functions ¶
func CollectionNote ¶
CollectionNote returns a stable human-readable reason (max ~512 chars for schema).
func CommName ¶ added in v0.55.0
CommName is a process name cut to what the kernel stores, so it can be compared with what the kernel reports.
func EnvLocaleC ¶
func EnvLocaleC() []string
EnvLocaleC forces C locale for deterministic CLI output parsing.
func FileExistsRegular ¶ added in v0.5.0
FileExistsRegular reports whether path exists and is not a directory.
func HostIsContainerized ¶ added in v0.5.0
func HostIsContainerized() *bool
HostIsContainerized reports dockerenv/cgroup hints (best-effort).
func ProcessIsRunning ¶ added in v0.55.0
ProcessIsRunning reports whether a process of exactly this name is running.
-x, so "mysqld" does not also match "mysqld_safe": the wrapper can be up while the server it babysits is down, and reporting the wrapper as the service would be a confident wrong answer.
func ProcessRunningState ¶ added in v0.54.1
ProcessRunningState reports "running" when one of these processes is in the process table, and "" when none of them is.
It never answers "stopped". A name we do not find may be a service that is genuinely down, or the same service under a name this distribution chose differently — and reporting the second as "stopped" would be the very kind of confident wrong answer this function exists to replace. Saying "running" only when a process is really there adds knowledge without ever inventing any.
This is the last question asked, after the machine's own service list and after systemd, because those two also say when something is stopped.
func QueryDistroPackageVersion ¶ added in v0.28.0
QueryDistroPackageVersion returns the full distro package version for the first matching package name (e.g., "2.4.57-2~deb12u2" for apache2 on Debian, "2:3.5.25-1.el9" for postfix on RHEL). Tries dpkg-query (Debian/Ubuntu) then rpm (RHEL/CentOS). Returns "" on failure.
func ReadFileBounded ¶ added in v0.4.0
ReadFileBounded reads at most maxBytes from path (regular file open).
func ScanContextError ¶ added in v0.4.0
ScanContextError returns ctx.Err() when ctx is non-nil and done.
func ServiceStateFromList ¶ added in v0.54.1
func ServiceStateFromList(services []payload.ServiceEntry, want []string) string
ServiceStateFromList reports what this machine's own service list already says about any of these units: "running", "stopped", or "" if it says nothing.
Every posture used to ask for the systemd spelling only. On a machine with no systemd the answer was sitting in the payload and nothing could read it: the services block said apache2 was running, while apache_httpd_posture reported no service state at all. Six postures were blind this way on one Ubuntu 14.04 host — apache, postfix, ftp, redis, mongodb and mysql.
func TruncateRunes ¶
TruncateRunes truncates to at most max runes.
func UnitBaseName ¶ added in v0.54.1
UnitBaseName is a service's name without the ".service" systemd gives it.
The two init systems spell the same service differently: systemd lists "apache2.service", sysvinit and Upstart list "apache2". Comparing the spellings as they come makes every match miss on one kind of machine.
Types ¶
This section is empty.