From eceea29018825d9c4092d4cc455441f18655b7fe Mon Sep 17 00:00:00 2001 From: Nourdeo <45716441+Nourdeo@users.noreply.github.com> Date: Fri, 21 Nov 2025 11:40:29 +0400 Subject: [PATCH] Improve zpool status output parsing Refactor zpool status parsing to handle headers and indented rows. --- lib/puppet/provider/zpool/zpool.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/zpool/zpool.rb b/lib/puppet/provider/zpool/zpool.rb index 799ebdc..fc59218 100644 --- a/lib/puppet/provider/zpool/zpool.rb +++ b/lib/puppet/provider/zpool/zpool.rb @@ -73,7 +73,14 @@ def get_pool_data '' end out = execute("zpool status #{zpool_opts} #{@resource[:pool]}", failonfail: false, combine: false) - zpool_data = out.lines.select { |line| line.index("\t") == 0 }.map { |l| l.strip.split("\s")[0] } + lines = out.lines + # Skip until we reach the NAME/STATE/READ/WRITE/CKSUM header + lines = lines.drop_while { |l| !(l =~ /^\s*NAME\s+STATE\s+READ\s+WRITE\s+CKSUM/) } + # Now collect indented table rows (pool and vdevs) + zpool_data = lines + .select { |l| l =~ /^\s+/ } + .map { |l| l.strip.split(/\s+/)[0] } + # Drop the "NAME" header zpool_data.shift zpool_data end