Documentation
ΒΆ
Overview ΒΆ
Package lib provides a robust collection of built-in Checks and Notifiers for the checker framework. It functions as the "Standard Library" of the checker ecosystem, allowing you to monitor common infrastructure without writing custom check logic.
Included components range from system metrics (CPU, Memory, Disk, Uptime) powered by gopsutil, to network diagnostics (Ping, DNS, HTTP, Proxy), and command execution (Cmd, SSH). It also provides notifiers for Logging, debugging, and mobile alerts via Pushover.
Usage in Go ΒΆ
You can instantiate checks directly using their exported functions (e.g., Http, Cpu, Ping) and add them to a Checker instance via `AddCheck`.
The JSON Registry (Inner Workings) ΒΆ
What makes the lib package powerful is its integration with the checker's JSON configuration system.
Upon package initialization (in `init()`), the lib package automatically registers a series of "Makers" (implementing [checker.CheckMaker] and [checker.NotifierMaker]) with the core checker registry. A Maker knows how to translate a generic JSON payload into a concrete arguments struct (like HttpArgs or CpuArgs) and eventually instantiate the actual Check or Notifier function.
This enables a completely data-driven monitoring setup: you can compile a single Go binary that imports this package anonymously (`_ "github.com/.../lib"`), and users can configure complex monitoring pipelines entirely through JSON, including recursive wrappers like Less and Fail.
Testing and Mocking ΒΆ
The lib package is designed with testability in mind. Most hardware- and network-dependent calls (like reading from /proc, spawning OS processes, or dialing raw ICMP sockets) are abstracted into package-level variables internally. This allows the test suite to safely mock these interactions without relying on the host system's state or privileges.
Index ΒΆ
- func Cmd(analyze func(exitCode int, output string) (chkr.State, string), name string, ...) chkr.Check
- func Cpu(warnPercent, failPercent float64) chkr.Check
- func Debug(prefix string) chkr.Notifier
- func Disk(path string, warnPercent, failPercent float64) chkr.Check
- func Dns(dns, hostname, address string) chkr.Check
- func Email(smtpServer, user, password string, to []string, opts ...EmailOption) chkr.Notifier
- func Fail(chk chkr.Check) chkr.Check
- func Http(method, url string, expected int) chkr.Check
- func Less(n chkr.Notifier) chkr.Notifier
- func Load(warnLoad5, failLoad5 float64) chkr.Check
- func Logging(logger *slog.Logger) chkr.Notifier
- func Mem(warnPercent, failPercent float64) chkr.Check
- func Ping(address string, warnMillis, failMillis int) chkr.Check
- func ProcExists(name string) chkr.Check
- func Proxy(method, request, proxy string, expected int) chkr.Check
- func Pushover(prefix, app, recipient string) chkr.Notifier
- func Ssh(analyze func(exitCode int, output string) (chkr.State, string), ...) (chkr.Check, error)
- func Swap(warnPercent, failPercent float64) chkr.Check
- func SysProcs(warnCount, failCount int) chkr.Check
- func Uptime(minUptime time.Duration) chkr.Check
- type CmdArgs
- type CpuArgs
- type DebugArgs
- type DiskArgs
- type DnsArgs
- type EmailArgs
- type EmailOption
- type FailArgs
- type HttpArgs
- type LessArgs
- type LoadArgs
- type LoggingArgs
- type MemArgs
- type PingArgs
- type ProcExistsArgs
- type ProxyArgs
- type PushoverArgs
- type SshArgs
- type SwapArgs
- type SysProcsArgs
- type UptimeArgs
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Cmd ΒΆ added in v0.2.0
func Cmd(analyze func(exitCode int, output string) (chkr.State, string), name string, args ...string) chkr.Check
Cmd returns a check that executes the given command and analyzes the results using the given analyze function. If analyze is nil a default analyzer function is used. This default function only considers the exit code of the called command (non zero exit code results in a failed check). Note: The default analyzer is also used when configuring this check using a json config file with checker.ReadConfig.
func Cpu ΒΆ added in v0.2.0
Cpu returns a check that verifies the system's total CPU usage percentage.
func Debug ΒΆ added in v0.3.0
Debug returns a notifier that prints the check state directly to stdout. It is primarily intended for debugging and development. It replaces any timestamp in the output with '2001-01-01 01:01:01' to make it deterministic for testing.
func Disk ΒΆ added in v0.2.0
Disk returns a check that verifies the disk usage percentage for a specific path.
func Dns ΒΆ
Dns returns a check that verifies the resolution of a hostname to a specific address using a given DNS server.
func Email ΒΆ added in v0.3.0
func Email(smtpServer, user, password string, to []string, opts ...EmailOption) chkr.Notifier
Email returns a notifier that sends emails via SMTP.
func Logging ΒΆ
Logging returns a notifier that outputs check results using structured logging. If logger is nil, slog.Default() is used.
func Mem ΒΆ added in v0.2.0
Mem returns a check that verifies the system's virtual memory usage percentage.
func ProcExists ΒΆ added in v0.2.0
ProcExists returns a check that verifies if at least one process with the exact given name is running.
func Ssh ΒΆ added in v0.2.0
func Ssh(analyze func(exitCode int, output string) (chkr.State, string), host, user, command string) (chkr.Check, error)
Ssh returns a check that executes the given command on the remote host using the system's ssh command and then analyzing the command output using the analyze function. If analyze is nil a default analyzer function is used. This default function only considers the exit code of the called command (non zero exit code results in a failed check).
Note: The default analyzer is also used when configuring this check using a json config file with checker.ReadConfig.
Note: Make sure public key authentication and host key authorization is configured correctly for the user running checker for the remote machine.
func Swap ΒΆ added in v0.2.0
Swap returns a check that verifies the system's swap memory usage percentage.
Types ΒΆ
type DebugArgs ΒΆ added in v0.3.0
type DebugArgs struct {
Prefix string
}
DebugArgs defines the arguments for a Debug notifier.
type EmailArgs ΒΆ added in v0.3.0
type EmailArgs struct {
SmtpServer string
User string
Password string
To []string
From string
Template string
}
EmailArgs defines the arguments for an Email notifier.
type EmailOption ΒΆ added in v0.3.0
type EmailOption func(*emailOptions)
EmailOption defines a functional option for the Email notifier.
func WithFrom ΒΆ added in v0.3.0
func WithFrom(from string) EmailOption
WithFrom returns an EmailOption that sets the sender address.
func WithTemplate ΒΆ added in v0.3.0
func WithTemplate(mailTemplate string) EmailOption
WithTemplate returns an EmailOption that sets a custom email body template.
type FailArgs ΒΆ
type FailArgs struct {
chkr.WithRecursion
Check chkr.CheckConfig
}
FailArgs defines the arguments for a Fail check wrapper.
type LessArgs ΒΆ
type LessArgs struct {
Notifier chkr.NotifierConfig
}
LessArgs defines the arguments for a Less notifier wrapper.
type LoggingArgs ΒΆ
type LoggingArgs struct {
// Optional: Static attributes that will be added to every log event.
Attributes map[string]string `json:"attributes,omitempty"`
}
LoggingArgs defines the arguments for a Logging notifier configured via JSON.
type ProcExistsArgs ΒΆ added in v0.2.0
type ProcExistsArgs struct {
Name string
}
ProcExistsArgs defines the arguments for a Process Exists check.
type PushoverArgs ΒΆ
PushoverArgs defines the arguments for a Pushover notifier.
type SysProcsArgs ΒΆ added in v0.2.0
SysProcsArgs defines the arguments for a Total Process Count check.
type UptimeArgs ΒΆ added in v0.2.0
type UptimeArgs struct {
MinMinutes uint64 // Warn if uptime is less than this value (e.g. recent reboot)
}
UptimeArgs defines the arguments for an Uptime check.