summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Cavalca <dcavalca@fb.com>2016-06-15 12:13:12 +0100
committerDavide Cavalca <dcavalca@fb.com>2016-06-15 12:13:12 +0100
commit071c93fd821b35941990881dfd8360beb507c120 (patch)
treecedde8986bc1e2f3263867af6ded006738e77fae
parent700f03d212948c976933b5d93ecb1d996c144544 (diff)
downloadohai-071c93fd821b35941990881dfd8360beb507c120.tar.gz
more robust parsing logic for ring_params
-rw-r--r--lib/ohai/plugins/linux/network.rb36
1 files changed, 18 insertions, 18 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index edf779f2..f6c34a21 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -178,24 +178,24 @@ Ohai.plugin(:Network) do
next unless iface[tmp_int][:encapsulation] == "Ethernet"
so = shell_out("#{ethtool_binary} -g #{tmp_int}")
Ohai::Log.debug("Parsing ethtool output: #{so.stdout}")
- # Nasty, brittle regex to capture the ethtool output
- nasty_regex =
-/Ring parameters for #{tmp_int}:
-Pre-set maximums:
-RX:\s+(\d+)
-.*
-TX:\s+(\d+)
-Current hardware settings:
-RX:\s+(\d+)
-.*
-TX:\s+(\d+)/m
- if nasty_regex.match(so.stdout)
- iface[tmp_int]["ring_params"] = {
- "max_rx" => $1.to_i,
- "max_tx" => $2.to_i,
- "current_rx" => $3.to_i,
- "current_tx" => $4.to_i,
- }
+ type = nil
+ iface[tmp_int]["ring_params"] = {}
+ so.stdout.lines.each do |line|
+ next if line.start_with?("Ring parameters for")
+ next if line.strip.nil?
+ if line =~ /Pre-set maximums/
+ type = "max"
+ next
+ end
+ if line =~ /Current hardware settings/
+ type = "current"
+ next
+ end
+ key, val = line.split(/:\s+/)
+ if type && val
+ ring_key = "#{type}_#{key.downcase.tr(' ', '_')}"
+ iface[tmp_int]["ring_params"][ring_key] = val.to_i
+ end
end
end
iface