From 1b41d8da97cd9daa2b7476906bd622c4a155ceed Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 25 Jul 2022 00:26:40 +0100 Subject: [PATCH] Improve disk state parsing for megaraid controllers --- cookbooks/hardware/templates/default/ohai.rb.erb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cookbooks/hardware/templates/default/ohai.rb.erb b/cookbooks/hardware/templates/default/ohai.rb.erb index 97a8823c2..343b095a4 100644 --- a/cookbooks/hardware/templates/default/ohai.rb.erb +++ b/cookbooks/hardware/templates/default/ohai.rb.erb @@ -496,8 +496,9 @@ Ohai.plugin(:Hardware) do devices[:disks] << disk controller[:disks] << disk[:id] array[:disks] << disk[:id] - elsif disk && line =~ /^Firmware state:\s+(.*\S),\s*(.*\S)\s*$/ - case Regexp.last_match(1) + elsif disk && line =~ /^Firmware state:\s+(\S.*)$/ + status, state = Regexp.last_match(1).split(/,\s*/) + case status when "Unconfigured(good)" then disk[:status] = "unconfigured" when "Unconfigured(bad)" then disk[:status] = "unconfigured" when "Hotspare" then disk[:status] = "hotspare" @@ -508,7 +509,7 @@ Ohai.plugin(:Hardware) do when "Copyback" then disk[:status] = "rebuilding" else disk[:status] = "unknown" end - case Regexp.last_match(2) + case state when "Spun Up" then disk[:state] = "spun_up" when "Spun down" then disk[:state] = "spun_down" else disk[:state] = "unknown" @@ -554,8 +555,9 @@ Ohai.plugin(:Hardware) do devices[:disks] << disk end - elsif disk && line =~ /^Firmware state:\s+(.*\S),\s*(.*\S)\s*$/ - case Regexp.last_match(1) + elsif disk && line =~ /^Firmware state:\s+(\S.*)$/ + status, state = Regexp.last_match(1).split(/,\s*/) + case status when "Unconfigured(good)" then disk[:status] = "unconfigured" when "Unconfigured(bad)" then disk[:status] = "unconfigured" when "Hotspare" then disk[:status] = "hotspare" @@ -566,7 +568,7 @@ Ohai.plugin(:Hardware) do when "Copyback" then disk[:status] = "rebuilding" else disk[:status] = "unknown" end - case Regexp.last_match(2) + case state when "Spun Up" then disk[:state] = "spun_up" when "Spun down" then disk[:state] = "spun_down" else disk[:state] = "unknown" -- 2.39.5