Help us shape the future of Go! Take the 2026 Go Developer Survey

smartmon

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package smartmon lists the drives udisks2 exports with their SMART verdict and tells when that verdict may have changed, over D-Bus. It is read-only: it reads properties udisks2 already holds and never calls a method that refreshes SMART data, runs a self-test or changes a setting, so it can never trigger an authorization prompt. Policy (notify, clear, log) is the caller's: this package only reports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Drive

type Drive struct {
	Path          dbus.ObjectPath // the udisks2 drive object: the drive's identity
	Model, Serial string
	Failing       bool     // ATA SmartFailing, only when SmartSupported && SmartEnabled
	Warnings      []string // NVMe SmartCriticalWarning names; empty when healthy
}

Drive is one drive udisks2 exports and its SMART verdict.

type Monitor

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

Monitor lists udisks2's drives with their SMART verdict and reports when a verdict may have changed or a drive came or went. It is safe for concurrent use.

func Absent

func Absent() *Monitor

Absent returns a Monitor for a process with no system bus or no udisks2: Available is false, Drives is empty, neither returns an error, and Changed never fires.

func New

func New(conn *dbus.Conn, log *slog.Logger) *Monitor

New watches udisks2 on conn, a system bus connection the caller keeps open and closes. It adds match rules for SMART property changes on drive objects and for drives added or removed; udisks2 need not be running, as every rule names its well-known name, which the bus resolves when a signal is sent. Changes that happen before New returns are not reported: list them with Drives after New.

A failed match rule is logged once at WARN naming udisks2 and leaves Changed silent; Available and Drives still work. Nothing else is ever logged. A nil log discards.

func (*Monitor) Available

func (m *Monitor) Available(ctx context.Context) (bool, error)

Available reports whether udisks2 owns its name on the bus or the bus can start it: udisks2 is D-Bus activated, so an installed one is often not running until its first call, which Drives then makes.

func (*Monitor) Changed

func (m *Monitor) Changed() <-chan struct{}

Changed fires after udisks2 reports a SMART verdict property change on a drive, or a drive added or removed. Changes that arrive before the receiver reads coalesce into one. The channel is closed when the bus connection is lost (or closed by the caller); it is never closed by Absent or after a failed setup, where it simply never fires.

func (*Monitor) Drives

func (m *Monitor) Drives(ctx context.Context) ([]Drive, error)

Drives lists every drive udisks2 exports, sorted by object path, from one GetManagedObjects call. The call carries no FlagNoAutoStart, so it starts an installed udisks2 that is not running yet.

A drive with a property of an unexpected D-Bus type is left out and its error, naming the object path and the property, is joined into the returned error, while every well-formed drive is still returned: one bad drive never hides the others. A failed call returns no drives.

Jump to

Keyboard shortcuts

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