feat(log-sources): which logs a PVE or PBS node writes #61

Merged
christianmanivong merged 1 commits from feature/log-sources-2049 into main 2026-11-05 00:05:48 +00:00
6 changed files with 57 additions and 1 deletions

No files matched your search

+4
View File
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Log sources on both drivers (NetOrk/netork#2049), through napalm-device-types'
`LogSourcesMixin` (4.30.0): `get_log_sources()` reads the units journald holds entries for
and the log files running processes hold open, with the service or container writing each,
over the exec path as root.
- Scheduled jobs on both drivers (NetOrk/netork#1933, #56), through napalm-device-types'
`PosixScheduledJobsMixin`: `get_scheduled_jobs()` reads `/etc/crontab`, `/etc/cron.d`,
the user crontabs, the run-parts directories, `/etc/anacrontab` and every systemd timer
+2
View File
@@ -23,6 +23,7 @@ from napalm_device_types import (
KernelFactsMixin,
LicenseMixin,
ListeningSocketsMixin,
LogSourcesMixin,
OpenSshServerMixin,
PortSpec,
ServicePackagesMixin,
@@ -58,6 +59,7 @@ class ProxmoxBackupDriver(
KernelFactsMixin,
ServicePackagesMixin,
ListeningSocketsMixin,
LogSourcesMixin,
SystemIdentityMixin,
SystemdServicesMixin,
ProxmoxScheduledJobsMixin,
+2
View File
@@ -34,6 +34,7 @@ from napalm_device_types import (
KernelFactsMixin,
LicenseMixin,
ListeningSocketsMixin,
LogSourcesMixin,
OpenSshServerMixin,
PortSpec,
ServicePackagesMixin,
@@ -93,6 +94,7 @@ class ProxmoxDriver(
KernelFactsMixin,
ServicePackagesMixin,
ListeningSocketsMixin,
LogSourcesMixin,
SystemIdentityMixin,
SystemdServicesMixin,
ProxmoxScheduledJobsMixin,
+5
View File
@@ -75,6 +75,11 @@ class ProxmoxHostMixin:
the exec path, which runs as root either way."""
return str(self._exec_ssh_command(command))
def _run_log_sources_command(self, command: str, *, privileged: bool) -> str:
"""The transport for ``LogSourcesMixin.get_log_sources``: the exec path,
which runs as root either way."""
return str(self._exec_ssh_command(command))
def get_packages(self) -> list[PackageDict]:
"""Return installed Debian packages with available-update info.
+1 -1
View File
@@ -21,7 +21,7 @@ classifiers = [
requires-python = ">=3.12"
dependencies = [
"napalm>=5.0.0",
"napalm_device_types>=4.27.0", # PosixScheduledJobsMixin
"napalm_device_types>=4.30.0", # LogSourcesMixin
"paramiko>=5.0.0", # CVE-2026-44405; imported directly for the node's SSH session (_base.py)
"proxmoxer>=2.0.0",
"netaddr>=0.9.0",
+43
View File
@@ -0,0 +1,43 @@
"""`get_log_sources`: which logs the node writes, and which service writes each.
pveproxy, pvedaemon, the Ceph daemons and a backup server's proxy write to
journald and to files under ``/var/log``. The command and its parse are
napalm-device-types'; the driver only carries the command over its exec path,
which already runs as root (NetOrk/netork#2049).
"""
from __future__ import annotations
from unittest.mock import patch
from napalm_device_types import LogSourcesMixin
from napalm_proxmox.backup_driver import ProxmoxBackupDriver
from napalm_proxmox.driver import ProxmoxDriver
WIRE = (
"LOGS_BEGIN\n[journald]\npveproxy.service\n"
"[open]\n/proc/2101/fd/7 /var/log/pveproxy/access.log\n"
"[stat]\n/proc/2101/fd/7 4096 1762250200\n"
"[cgroups]\n2101 0::/system.slice/pveproxy.service\n"
"[comm]\n2101 pveproxy worker\n"
"LOGS_END\n"
)
def test_both_drivers_declare_the_contract():
assert issubclass(ProxmoxDriver, LogSourcesMixin)
assert issubclass(ProxmoxBackupDriver, LogSourcesMixin)
def test_it_reads_as_root_over_the_exec_path(driver):
with patch.object(driver, "_exec_ssh_command", return_value=WIRE) as exec_:
reading = driver.get_log_sources()
[command] = [c.args[0] for c in exec_.call_args_list]
assert command.startswith("sh -c '")
assert reading["attributed"] is True
access = [s for s in reading["sources"] if s["kind"] == "file"]
assert [(s["path"], s["unit"]) for s in access] == [
("/var/log/pveproxy/access.log", "pveproxy")
]