Inventory Linux whole disks and account mounted filesystems by block topology

This commit is contained in:
2026-11-20 09:34:17 +01:00
parent 131cc53de2
commit eaaa6ff228
3 changed files with 439 additions and 4 deletions
+11 -3
View File
@@ -4,6 +4,7 @@ use crate::{
actions::{ServiceUnit, reboot_required},
process,
};
mod disks;
use rmm_domain::inventory_document::{CpuTimes, DeviceType, firmware_identifier};
use std::{
collections::BTreeMap,
@@ -200,6 +201,8 @@ pub struct Dns {
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct Volume {
#[serde(skip)]
pub(crate) devno: String,
pub mount_point: String,
pub filesystem: String,
pub device: String,
@@ -275,6 +278,7 @@ pub struct LinuxInventory {
pub routes: Observation<Vec<Route>>,
pub dns: Observation<Dns>,
pub volumes: Observation<Vec<Observation<Volume>>>,
pub disks: Observation<Vec<disks::Disk>>,
pub software: Observation<Vec<SoftwarePackage>>,
pub users: Observation<Vec<String>>,
pub updates: Observation<UpdateStatus>,
@@ -282,6 +286,8 @@ pub struct LinuxInventory {
pub smart: Observation<()>,
}
pub fn collect_native() -> LinuxInventory {
let volumes = volumes();
let disks = disks::collect(&volumes);
LinuxInventory {
os: operating_system(),
cpu: cpu(),
@@ -289,7 +295,8 @@ pub fn collect_native() -> LinuxInventory {
interfaces: interfaces(),
routes: routes(),
dns: dns(),
volumes: volumes(),
volumes,
disks,
software: software(),
users: logged_in_users(),
updates: updates(),
@@ -937,7 +944,7 @@ pub fn volumes() -> Observation<Vec<Observation<Volume>>> {
));
continue;
};
observations.push(volume(&mount, right[0], right[1]));
observations.push(volume(&mount, left[2], right[0], right[1]));
}
Some(observations)
})
@@ -955,7 +962,7 @@ impl Observation<Vec<Observation<Volume>>> {
self
}
}
fn volume(mount: &str, filesystem: &str, device: &str) -> Observation<Volume> {
fn volume(mount: &str, devno: &str, filesystem: &str, device: &str) -> Observation<Volume> {
// Remote filesystems can hang statvfs indefinitely; explicitly do not probe.
const LOCAL: &[&str] = &[
"ext2", "ext3", "ext4", "xfs", "btrfs", "tmpfs", "overlay", "vfat", "exfat", "f2fs", "zfs",
@@ -999,6 +1006,7 @@ fn volume(mount: &str, filesystem: &str, device: &str) -> Observation<Volume> {
Observation::valid(
&source,
Volume {
devno: devno.to_owned(),
mount_point: mount.into(),
filesystem: filesystem.into(),
device: mount_unescape(device).unwrap_or_else(|| device.into()),