systeminfo

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package systeminfo is a generated GoMock package.

Index

Constants

View Source
const (
	// PCI class codes for graphics devices
	VGACompatibleController = "0x030000" // VGA compatible controller
	DisplayController       = "0x038000" // Other display controller

	// Class code prefixes for graphics devices
	VGAPrefix     = "0x0300" // Prefix for VGA compatible devices
	DisplayPrefix = "0x0380" // Prefix for other display controllers
)
View Source
const (
	// DefaultBootIDPath is the path to the boot ID file.
	DefaultBootIDPath = "/proc/sys/kernel/random/boot_id"
	// SystemBootFileName is the name of the file where the system boot status is stored.
	SystemBootFileName = "system.json"
	// HardwareMapFileName is the name of the file where the hardware map is stored.
	HardwareMapFileName = "hardware-map.json"
)
View Source
const (

	// ScriptOverrideDir is the directory where custom/overide scripts are stored
	ScriptOverrideDir = "collect.d"
)

Variables

View Source
var DefaultInfoKeys = []string{
	"hostname",
	"architecture",
	"kernel",
	"distro_name",
	"distro_version",
	"product_name",
	"product_uuid",
	"default_interface",
	"default_ip_address",
	"default_mac_address",
}

DefaultInfoKeys is a list of default keys to be used when generating facts

View Source
var SupportedInfoKeys = map[string]func(info *Info) string{
	"hostname":     func(i *Info) string { return i.Hostname },
	"architecture": func(i *Info) string { return i.Architecture },
	"kernel":       func(i *Info) string { return i.Kernel },
	"distro_name": func(i *Info) string {
		if i.Distribution == nil {
			return ""
		}
		if val, ok := i.Distribution["name"]; ok {
			if s, ok := val.(string); ok {
				return s
			}
			return fmt.Sprint(val)
		}
		return ""
	},
	"distro_version": func(i *Info) string {
		if i.Distribution == nil {
			return ""
		}
		if val, ok := i.Distribution["version"]; ok {
			if str, ok := val.(string); ok {
				return str
			}
			return fmt.Sprint(val)
		}
		return ""
	},
	"product_name": func(i *Info) string {
		if i.Hardware.System != nil {
			return i.Hardware.System.ProductName
		}
		return ""
	},
	"product_serial": func(i *Info) string {
		if i.Hardware.System != nil {
			return i.Hardware.System.SerialNumber
		}
		return ""
	},
	"product_uuid": func(i *Info) string {
		if i.Hardware.System != nil {
			return i.Hardware.System.UUID
		}
		return ""
	},
	"bios_vendor": func(i *Info) string {
		if i.Hardware.BIOS != nil {
			return i.Hardware.BIOS.Vendor
		}
		return ""
	},
	"bios_version": func(i *Info) string {
		if i.Hardware.BIOS != nil {
			return i.Hardware.BIOS.Version
		}
		return ""
	},
	"default_interface": func(i *Info) string {
		if i.Hardware.Network != nil && i.Hardware.Network.DefaultRoute != nil {
			return i.Hardware.Network.DefaultRoute.Interface
		}
		return ""
	},
	"default_ip_address": func(i *Info) string {
		if i.Hardware.Network == nil || i.Hardware.Network.DefaultRoute == nil {
			return ""
		}
		dr := i.Hardware.Network.DefaultRoute
		for _, iface := range i.Hardware.Network.Interfaces {
			if iface.Name == dr.Interface {
				if len(iface.IPAddresses) == 0 {
					return ""
				}

				for _, addr := range iface.IPAddresses {
					ip := net.ParseIP(strings.Split(addr, "/")[0])
					if ip != nil && !ip.IsLinkLocalUnicast() {
						return addr
					}
				}

				return iface.IPAddresses[0]
			}
		}
		return ""
	},
	"default_mac_address": func(i *Info) string {
		if i.Hardware.Network == nil || i.Hardware.Network.DefaultRoute == nil {
			return ""
		}
		dr := i.Hardware.Network.DefaultRoute
		for _, iface := range i.Hardware.Network.Interfaces {
			if iface.Name == dr.Interface {
				return iface.MACAddress
			}
		}
		return ""
	},
	"gpu": func(i *Info) string {
		if len(i.Hardware.GPU) == 0 {
			return ""
		}

		var parts []string
		for idx, gpu := range i.Hardware.GPU {
			parts = append(parts, fmt.Sprintf("[%d] %s %s", idx, gpu.Vendor, gpu.Model))
		}
		return strings.Join(parts, "; ")
	},
	"total_memory_mb": func(i *Info) string {
		if i.Hardware.Memory == nil || i.Hardware.Memory.TotalKB <= 0 {
			return ""
		}
		return fmt.Sprintf("%d", i.Hardware.Memory.TotalKB/1024)
	},
	"cpu_cores": func(i *Info) string {
		if i.Hardware.CPU != nil {
			return fmt.Sprintf("%d", i.Hardware.CPU.TotalCores)
		}
		return ""
	},
	"cpu_processors": func(i *Info) string {
		if i.Hardware.CPU != nil {
			return fmt.Sprintf("%d", len(i.Hardware.CPU.Processors))
		}
		return ""
	},
	"cpu_model": func(i *Info) string {
		if i.Hardware.CPU != nil && len(i.Hardware.CPU.Processors) > 0 {
			return i.Hardware.CPU.Processors[0].Model
		}
		return ""
	},
}

SupportedInfoKeys is a map of supported info keys to their corresponding functions.

Functions

func GenerateFacts

func GenerateFacts(ctx context.Context, log *log.PrefixLogger, reader fileio.Reader, exec executer.Executer, info *Info, keys []string, dataDir string) map[string]string

GenerateFacts generates a map of facts based on the provided keys and system information

func NewManager

func NewManager(
	log *log.PrefixLogger,
	exec executer.Executer,
	readWriter fileio.ReadWriter,
	dataDir string,
	factKeys []string,
	collectionTimeout util.Duration,
) *manager

Types

type BIOSInfo

type BIOSInfo struct {
	Vendor  string `json:"vendor"`
	Version string `json:"version"`
	Date    string `json:"date,omitempty"`
}

BIOSInfo represents BIOS information

type BlockInfo

type BlockInfo struct {
	TotalSizeBytes uint64      `json:"total_size_bytes"`
	TotalSizeGB    float64     `json:"total_size_gb"`
	Disks          []DiskInfo  `json:"disks"`
	Mounts         []MountInfo `json:"mounts,omitempty"`
}

BlockInfo represents block device information

type Boot

type Boot struct {
	// Time is the time the system was booted.
	Time string `json:"bootTime,omitempty"`
	// ID is the unique boot ID populated by the kernel.
	ID string `json:"bootID,omitempty"`
}

func (*Boot) IsEmpty

func (b *Boot) IsEmpty() bool

type CPUInfo

type CPUInfo struct {
	TotalCores   int             `json:"total_cores"`
	TotalThreads int             `json:"total_threads"`
	Architecture string          `json:"architecture"`
	Processors   []ProcessorInfo `json:"processors"`
}

CPUInfo represents CPU information

type DefaultRoute

type DefaultRoute struct {
	Interface string `json:"interface"`
	Gateway   string `json:"gateway"`
	Family    string `json:"family"` // "ipv4" or "ipv6"
}

DefaultRoute represents the default network route for IPv4 or IPv6.

type DiskInfo

type DiskInfo struct {
	Name              string          `json:"name"`
	SizeBytes         uint64          `json:"size_bytes"`
	SizeGB            float64         `json:"size_gb"`
	DriveType         string          `json:"drive_type"`
	StorageController string          `json:"storage_controller"`
	Vendor            string          `json:"vendor,omitempty"`
	Model             string          `json:"model,omitempty"`
	SerialNumber      string          `json:"serial_number,omitempty"`
	WWN               string          `json:"wwn,omitempty"`
	BusType           string          `json:"bus_type,omitempty"`
	Partitions        []PartitionInfo `json:"partitions,omitempty"`
}

DiskInfo contains information about a single disk

type GPUDeviceInfo

type GPUDeviceInfo struct {
	Index       int    `json:"index"`
	Vendor      string `json:"vendor"`
	Model       string `json:"model"`
	DeviceID    string `json:"device_id,omitempty"`
	PCIAddress  string `json:"pci_address,omitempty"`
	RevisionID  string `json:"revision_id,omitempty"`
	VendorID    string `json:"vendor_id,omitempty"`
	MemoryBytes uint64 `json:"memory_bytes,omitempty"`
}

GPUDeviceInfo contains information about a GPU device

type GPUInfo

type GPUInfo struct {
	GPUs []GPUDeviceInfo `json:"gpus"`
}

GPUInfo represents GPU information

type HardwareFacts

type HardwareFacts struct {
	CPU     *CPUInfo        `json:"cpu,omitempty"`
	Memory  *MemoryInfo     `json:"memory,omitempty"`
	Block   *BlockInfo      `json:"block,omitempty"`
	Network *NetworkInfo    `json:"network,omitempty"`
	GPU     []GPUDeviceInfo `json:"gpu,omitempty"`
	BIOS    *BIOSInfo       `json:"bios,omitempty"`
	System  *SystemInfo     `json:"system,omitempty"`
}

HardwareFacts contains hardware information gathered by ghw

type Info

type Info struct {
	Hostname     string                 `json:"hostname"`
	Architecture string                 `json:"architecture"`
	Kernel       string                 `json:"kernel"`
	Distribution map[string]interface{} `json:"distribution,omitempty"`
	Hardware     HardwareFacts          `json:"hardware"`
	CollectedAt  string                 `json:"collected_at"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
	Boot         Boot                   `json:"boot,omitempty"`
}

func CollectInfo

func CollectInfo(ctx context.Context, log *log.PrefixLogger, exec executer.Executer, reader fileio.Reader, hardwareMapFilePath string) (*Info, error)

CollectInfo collects system information and returns a SystemInfoReport

type InterfaceInfo

type InterfaceInfo struct {
	Name        string   `json:"name"`
	MACAddress  string   `json:"mac_address"`
	IsVirtual   bool     `json:"is_virtual"`
	IPAddresses []string `json:"ip_addresses,omitempty"`
	MTU         int      `json:"mtu,omitempty"`
	Status      string   `json:"status,omitempty"`
}

InterfaceInfo contains information about a network interface

type Manager

type Manager interface {
	// IsRebooted checks if the system has been rebooted since the last time the agent started
	IsRebooted() bool
	// BootID returns the unique boot ID populated by the kernel
	BootID() string
	// BootTime returns the time the system was booted
	BootTime() string
	// ReloadStatus collects system info and sends a patch status to the management API
	ReloadStatus() error
	status.Exporter
}

type MemoryInfo

type MemoryInfo struct {
	TotalKB uint64                 `json:"total_kb"`
	Details map[string]interface{} `json:"details,omitempty"`
}

MemoryInfo represents memory information

type MockManager

type MockManager struct {
	// contains filtered or unexported fields
}

MockManager is a mock of Manager interface.

func NewMockManager

func NewMockManager(ctrl *gomock.Controller) *MockManager

NewMockManager creates a new mock instance.

func (*MockManager) BootID

func (m *MockManager) BootID() string

BootID mocks base method.

func (*MockManager) BootTime

func (m *MockManager) BootTime() string

BootTime mocks base method.

func (*MockManager) EXPECT

func (m *MockManager) EXPECT() *MockManagerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockManager) IsRebooted

func (m *MockManager) IsRebooted() bool

IsRebooted mocks base method.

func (*MockManager) ReloadStatus

func (m *MockManager) ReloadStatus() error

ReloadStatus mocks base method.

func (*MockManager) Status

func (m *MockManager) Status(arg0 context.Context, arg1 *v1alpha1.DeviceStatus) error

Status mocks base method.

type MockManagerMockRecorder

type MockManagerMockRecorder struct {
	// contains filtered or unexported fields
}

MockManagerMockRecorder is the mock recorder for MockManager.

func (*MockManagerMockRecorder) BootID

func (mr *MockManagerMockRecorder) BootID() *gomock.Call

BootID indicates an expected call of BootID.

func (*MockManagerMockRecorder) BootTime

func (mr *MockManagerMockRecorder) BootTime() *gomock.Call

BootTime indicates an expected call of BootTime.

func (*MockManagerMockRecorder) IsRebooted

func (mr *MockManagerMockRecorder) IsRebooted() *gomock.Call

IsRebooted indicates an expected call of IsRebooted.

func (*MockManagerMockRecorder) ReloadStatus

func (mr *MockManagerMockRecorder) ReloadStatus() *gomock.Call

ReloadStatus indicates an expected call of ReloadStatus.

func (*MockManagerMockRecorder) Status

func (mr *MockManagerMockRecorder) Status(arg0, arg1 any) *gomock.Call

Status indicates an expected call of Status.

type MountInfo

type MountInfo struct {
	Device     string `json:"device"`
	MountPoint string `json:"mount_point"`
	FSType     string `json:"fs_type"`
	Options    string `json:"options"`
}

MountInfo contains information about a filesystem mount

type NetworkInfo

type NetworkInfo struct {
	Interfaces   []InterfaceInfo `json:"interfaces"`
	DefaultRoute *DefaultRoute   `json:"default_route,omitempty"`
	DNSServers   []string        `json:"dns_servers,omitempty"`
	FQDN         string          `json:"fqdn,omitempty"`
}

NetworkInfo represents network information

type PCIModelInfo

type PCIModelInfo struct {
	PCIID   string `yaml:"pciID"`
	PCIName string `yaml:"pciName"`
}

PCIModelInfo contains information about a specific GPU model

type PCIVendorInfo

type PCIVendorInfo struct {
	Models     []PCIModelInfo `yaml:"models"`
	VendorID   string         `yaml:"vendorID"`
	VendorName string         `yaml:"vendorName"`
}

PCIVendorInfo contains mapping information for vendors and models

type PartitionInfo

type PartitionInfo struct {
	Name       string  `json:"name"`
	SizeBytes  uint64  `json:"size_bytes"`
	SizeGB     float64 `json:"size_gb"`
	MountPoint string  `json:"mount_point,omitempty"`
	Type       string  `json:"type,omitempty"`
	IsReadOnly bool    `json:"is_read_only,omitempty"`
}

PartitionInfo contains information about a disk partition

type ProcessorInfo

type ProcessorInfo struct {
	ID                int      `json:"id"`
	NumCores          int      `json:"num_cores"`
	NumThreads        int      `json:"num_threads"`
	NumThreadsPerCore int      `json:"num_threads_per_core"`
	Vendor            string   `json:"vendor"`
	Model             string   `json:"model"`
	Capabilities      []string `json:"capabilities,omitempty"`
}

ProcessorInfo contains information about a single processor

type SystemInfo

type SystemInfo struct {
	Manufacturer string `json:"manufacturer"`
	ProductName  string `json:"product_name"`
	SerialNumber string `json:"serial_number,omitempty"`
	UUID         string `json:"uuid,omitempty"`
	Version      string `json:"version,omitempty"`
	Family       string `json:"family,omitempty"`
	SKU          string `json:"sku,omitempty"`
}

SystemInfo represents system information

Jump to

Keyboard shortcuts

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