32 lines
868 B
Go
32 lines
868 B
Go
package sysinfo
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// Context carries helpers every Collector may need.
|
|
type Context struct {
|
|
Now time.Time
|
|
Logf func(string, ...any)
|
|
Run func(string, ...string) ([]byte, error)
|
|
SafeRun func(string, ...string) string
|
|
SafeRead func(string) string
|
|
}
|
|
|
|
// Collector gathers one snapshot section.
|
|
type Collector interface {
|
|
// SectionKey becomes the JSON field name (e.g. "system", "zfs").
|
|
SectionKey() string
|
|
|
|
// EnsurePrerequisites installs/verifies required tools via the
|
|
// provided PackageManager. Must be idempotent.
|
|
EnsurePrerequisites(pm PackageManager, ctx *Context) error
|
|
|
|
// IsSupported decides if CollectData should run on this machine.
|
|
IsSupported(pm PackageManager, ctx *Context) bool
|
|
|
|
// CollectData returns the JSON blob for this section.
|
|
CollectData(ctx *Context) (json.RawMessage, error)
|
|
}
|