diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-11-17 16:21:23 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-11-17 16:21:23 -0800 |
commit | 0f9e809a579748bea07d504abdb578099f884e9e (patch) | |
tree | 22cd9c6649df36f2b821f8c01df9c64dc7d5f736 /lib | |
parent | 4fe1390dc3b1d4b91398cb95d8550228b7c8dfcc (diff) | |
download | ohai-0f9e809a579748bea07d504abdb578099f884e9e.tar.gz |
Use pure ruby vs. shelling out to grep to parse netstat data
Besides avoiding potentially pathing issues with grep this is faster:
```
Comparison:
pure_ruby: 55.9 i/s
grep: 41.6 i/s - 1.34x (± 0.00) slower
```
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ohai/plugins/aix/network.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb index 02d064e7..f36c3dd8 100644 --- a/lib/ohai/plugins/aix/network.rb +++ b/lib/ohai/plugins/aix/network.rb @@ -44,16 +44,16 @@ Ohai.plugin(:Network) do # We unfortunately have to do things a bit different here, if ohai is running # within a WPAR. For instance, the WPAR isn't aware of some of its own networking - # minutia such as default gateway/route. + # minutia such as default gateway/route. lpars return 0 here. wpars return > 0 unless shell_out("uname -W").stdout.to_i > 0 # :default_interface, :default_gateway - route -n get 0 - so = shell_out("netstat -rn |grep default") - so.stdout.lines.each do |line| + netstat_so = shell_out("netstat -rn").stdout + netstat_so.each_line do |line| + next unless line.start_with?('default') items = line.split(" ") - if items[0] == "default" - network[:default_gateway] = items[1] - network[:default_interface] = items[5] - end + network[:default_gateway] = items[1] + network[:default_interface] = items[5] + return end end |