Class: Pvectl::Parsers::SmartText

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/parsers/smart_text.rb

Overview

Parses smartctl text output (NVMe/SAS) into structured key-value pairs.

NVMe and SAS disks return SMART data as plain text from the Proxmox API (field text in GET /nodes/{node}/disks/smart). This parser extracts Key: Value lines into an Array of Hashes suitable for table display.

Examples:

Parsing NVMe SMART text

text = "Critical Warning:  0x00\nTemperature:  34 Celsius\n"
Pvectl::Parsers::SmartText.parse(text)
# => [{ "Attribute" => "Critical Warning", "Value" => "0x00" },
#     { "Attribute" => "Temperature", "Value" => "34 Celsius" }]

Class Method Summary collapse

Class Method Details

.parse(text) ⇒ Array<Hash{String => String}>

Parses smartctl text output into structured attributes.

Splits each line on the first colon. Lines without a colon or without a non-empty value after the colon are skipped. Uses String#split instead of regex to avoid ReDoS risk.

Parameters:

  • text (String, nil)

    raw smartctl text output

Returns:

  • (Array<Hash{String => String}>)

    parsed attributes



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pvectl/parsers/smart_text.rb', line 26

def self.parse(text)
  return [] if text.nil? || text.empty?

  text.each_line.filter_map { |line|
    key, value = line.strip.split(":", 2)
    next unless value

    key = key.strip
    value = value.strip
    next if key.empty? || value.empty?

    { "Attribute" => key, "Value" => value }
  }
end