refactor read_sysfs

add pve_mod_version api
This commit is contained in:
Meliox 2026-01-11 11:19:17 +01:00
parent 5855e8be25
commit f76a4c23d7

View File

@ -995,26 +995,6 @@ sub _get_cpu_name {
return $enhanced_json; return $enhanced_json;
} }
sub read_sysfs {
my ($path) = @_;
return "unknown" unless defined $path && -f $path;
if (open my $fh, '<', $path) {
my $value = <$fh>;
close $fh;
if (defined $value) {
chomp $value;
# Remove leading/trailing whitespace
$value =~ s/^\s+|\s+$//g;
return $value ne '' ? $value : "unknown";
}
}
return "unknown";
}
# Helper function to get CPU model by package ID # Helper function to get CPU model by package ID
sub _cpu_model_by_package { sub _cpu_model_by_package {
my ($pkg) = @_; my ($pkg) = @_;
@ -1176,6 +1156,26 @@ sub _parse_upsc_output {
# Supporting functions # Supporting functions
# ============================================================================ # ============================================================================
sub read_sysfs {
my ($path) = @_;
return "unknown" unless defined $path && -f $path;
if (open my $fh, '<', $path) {
my $value = <$fh>;
close $fh;
if (defined $value) {
chomp $value;
# Remove leading/trailing whitespace
$value =~ s/^\s+|\s+$//g;
return $value ne '' ? $value : "unknown";
}
}
return "unknown";
}
sub _is_process_alive { sub _is_process_alive {
my ($pid) = @_; my ($pid) = @_;
return -d "/proc/$pid"; return -d "/proc/$pid";
@ -1450,6 +1450,10 @@ sub get_ups_stats {
return $ups_data; return $ups_data;
} }
sub get_pve_mod_version {
return $VERSION;
}
# ============================================================================ # ============================================================================
# Main Collector # Main Collector
# ============================================================================ # ============================================================================