driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Failing after 4s
driver / test (3.12) (pull_request) Successful in 55s
driver / types (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 57s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m10s
CI / driver (pull_request) Failing after 2m27s
driver / publish (pull_request) Skipped
net-snmp on OpenBSD answers ssCpuIdle with 0 on an idle host (and hrProcessorLoad with 100), so a reading of the standard OID shows every OpenBSD host at 100 % CPU. The profile now marks the CPU unknown, and the application reports no figure instead of a wrong one. Memory, swap and load stay on the standard reading. Closes #7
97 lines
3.9 KiB
Python
97 lines
3.9 KiB
Python
"""OpenBSD: hw.* sysctls for the hardware, uname for release and kernel."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import ClassVar
|
|
|
|
from napalm_device_types import FingerprintRule, SnmpHealthProfile
|
|
|
|
from napalm_bsd import parse
|
|
from napalm_bsd.base import BASE_SYSTEM, BsdDriver
|
|
|
|
|
|
class OpenBSDDriver(BsdDriver):
|
|
"""NAPALM driver for OpenBSD hosts, over SSH."""
|
|
|
|
TYPE_LABEL = "OpenBSD"
|
|
VENDOR = "OpenBSD"
|
|
DRIVER_NAME = "openbsd"
|
|
# OpenBSD's SSH banner names no OS; its sysDescr does ("OpenBSD host 7.9 GENERIC.MP#449").
|
|
SNMP_FINGERPRINT = [FingerprintRule("openbsd", weight=5.0)]
|
|
# net-snmp maps OpenBSD's CPU states wrongly: ssCpuIdle is 0 on an idle host, and
|
|
# hrProcessorLoad 100. No figure beats one that says the host is always busy (#7).
|
|
SNMP_HEALTH_PROFILE: ClassVar[SnmpHealthProfile] = {"cpu": {"unknown": True}}
|
|
|
|
OS_VERSION_COMMAND = "uname -sr"
|
|
# The kernel's build, e.g. GENERIC.MP#449; the release is in uname -r.
|
|
KERNEL_COMMAND = "uname -v"
|
|
# A sysctl node the machine lacks fails on its own and prints nothing.
|
|
PLATFORM_COMMAND = (
|
|
"for k in vendor product serialno; do "
|
|
'printf "%s=%s\\n" "$k" "$(sysctl -n hw.$k 2>/dev/null)"; done'
|
|
)
|
|
|
|
# fstat shows a user only their own processes; netstat shows every socket, unnamed.
|
|
LISTENING_COMMAND = "fstat -n"
|
|
LISTENING_FALLBACK_COMMAND = "netstat -an -f inet; netstat -an -f inet6"
|
|
|
|
def _parse_listening(self, output: str, *, attributed: bool) -> list[dict]:
|
|
return parse.fstat_sockets(output) if attributed else parse.netstat_listening(output)
|
|
|
|
INSTALL_COMMAND = "pkg_add -I {name}"
|
|
UNINSTALL_COMMAND = "pkg_delete {name}"
|
|
# rcctl check needs no root; "rcctl ls started" does.
|
|
SERVICE_STATUS_COMMAND = (
|
|
"for s in $(rcctl ls on); do "
|
|
"if rcctl check $s >/dev/null 2>&1; then r=1; else r=0; fi; "
|
|
'printf "%s\\t%s\\n" "$s" "$r"; done'
|
|
)
|
|
SERVICE_ACTION_COMMAND = "rcctl {action} {name}"
|
|
SNMPD_CONF = "/etc/snmp/snmpd.conf"
|
|
# net-snmp's rc script; "snmpd" is OpenBSD's own daemon.
|
|
SNMPD_START = "rcctl enable netsnmpd && rcctl restart netsnmpd"
|
|
|
|
def _parse_services(self, output: str) -> list[dict]:
|
|
return parse.rcctl_check(output)
|
|
|
|
def get_services(self) -> list[dict]:
|
|
return self._parse_services(self._out(self.SERVICE_STATUS_COMMAND, timeout=120))
|
|
|
|
def get_packages(self) -> list[dict]:
|
|
return parse.pkg_info(self._out("pkg_info"))
|
|
|
|
def get_available_updates(self) -> list[dict]:
|
|
"""Package updates from ``pkg_add -u -n -v``, and the base system's syspatches.
|
|
|
|
syspatch applies its patches together and in order, so they are one
|
|
entry (#799). Neither tool says which update is a security fix.
|
|
"""
|
|
updates: list[dict] = [
|
|
{**candidate, "origin": None, "security": None}
|
|
for candidate in parse.pkg_add_candidates(
|
|
self._read("pkg_add -u -n -v", privileged=True, timeout=300).stdout
|
|
)
|
|
]
|
|
patches = parse.syspatch(self._read("syspatch -c", privileged=True, timeout=120).stdout)
|
|
if patches:
|
|
installed = parse.syspatch(self._out("syspatch -l", privileged=True))
|
|
summary = (
|
|
", ".join(patches)
|
|
if len(patches) <= 3
|
|
else f"{len(patches)} patches: {patches[0]} … {patches[-1]}"
|
|
)
|
|
updates.append(
|
|
{
|
|
"name": BASE_SYSTEM,
|
|
"current_version": installed[-1] if installed else self._out("uname -r"),
|
|
"new_version": summary,
|
|
"origin": "syspatch",
|
|
"security": None,
|
|
}
|
|
)
|
|
return updates
|
|
|
|
def _hardware(self) -> tuple[str, str, str]:
|
|
hw = self._platform()
|
|
return hw.get("vendor", ""), hw.get("product", ""), hw.get("serialno", "")
|