Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
- index 7501b0b..5f6820b 100644
- --- a/lib/ohai/plugins/linux/network.rb
- +++ b/lib/ohai/plugins/linux/network.rb
- @@ -32,68 +32,72 @@ end
- iface = Mash.new
- net_counters = Mash.new
- +ifconfig_a = nil
- +
- popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
- stdin.close
- - cint = nil
- - stdout.each do |line|
- - tmp_addr = nil
- - if line =~ /^([0-9a-zA-Z\.\:\-]+)\s+/
- - cint = $1
- - iface[cint] = Mash.new
- - if cint =~ /^(\w+)(\d+.*)/
- - iface[cint][:type] = $1
- - iface[cint][:number] = $2
- - end
- - end
- - if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/
- - iface[cint][:encapsulation] = encaps_lookup($1)
- - end
- - if line =~ /HWaddr (.+?)\s/
- - iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
- - iface[cint][:addresses][$1] = { "family" => "lladdr" }
- - end
- - if line =~ /inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
- - iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
- - iface[cint][:addresses][$1] = { "family" => "inet" }
- - tmp_addr = $1
- - end
- - if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/
- - iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
- - iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) }
- - end
- - if line =~ /Bcast:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
- - iface[cint][:addresses][tmp_addr]["broadcast"] = $1
- - end
- - if line =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
- - iface[cint][:addresses][tmp_addr]["netmask"] = $1
- - end
- - flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)\s/)
- - if flags.length > 1
- - iface[cint][:flags] = flags.flatten
- - end
- - if line =~ /MTU:(\d+)/
- - iface[cint][:mtu] = $1
- - end
- - if line =~ /RX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) frame:(\d+)/
- - net_counters[cint] = Mash.new unless net_counters[cint]
- - net_counters[cint][:rx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "frame" => $5 }
- - end
- - if line =~ /TX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) carrier:(\d+)/
- - net_counters[cint][:tx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "carrier" => $5 }
- - end
- - if line =~ /collisions:(\d+)/
- - net_counters[cint][:tx]["collisions"] = $1
- - end
- - if line =~ /txqueuelen:(\d+)/
- - net_counters[cint][:tx]["queuelen"] = $1
- - end
- - if line =~ /RX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
- - net_counters[cint][:rx]["bytes"] = $1
- - end
- - if line =~ /TX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
- - net_counters[cint][:tx]["bytes"] = $1
- + ifconfig_a = stdout.string
- +end
- +
- +cint = nil
- +ifconfig_a.split("\n").each do |line|
- + tmp_addr = nil
- + if line =~ /^([0-9a-zA-Z\.\:\-]+)\s+/
- + cint = $1
- + iface[cint] = Mash.new
- + if cint =~ /^(\w+)(\d+.*)/
- + iface[cint][:type] = $1
- + iface[cint][:number] = $2
- end
- end
- + if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/
- + iface[cint][:encapsulation] = encaps_lookup($1)
- + end
- + if line =~ /HWaddr (.+?)\s/
- + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
- + iface[cint][:addresses][$1] = { "family" => "lladdr" }
- + end
- + if line =~ /inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
- + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
- + iface[cint][:addresses][$1] = { "family" => "inet" }
- + tmp_addr = $1
- + end
- + if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/
- + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
- + iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) }
- + end
- + if line =~ /Bcast:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
- + iface[cint][:addresses][tmp_addr]["broadcast"] = $1
- + end
- + if line =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
- + iface[cint][:addresses][tmp_addr]["netmask"] = $1
- + end
- + flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)\s/)
- + if flags.length > 1
- + iface[cint][:flags] = flags.flatten
- + end
- + if line =~ /MTU:(\d+)/
- + iface[cint][:mtu] = $1
- + end
- + if line =~ /RX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) frame:(\d+)/
- + net_counters[cint] = Mash.new unless net_counters[cint]
- + net_counters[cint][:rx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "frame" => $5 }
- + end
- + if line =~ /TX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) carrier:(\d+)/
- + net_counters[cint][:tx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "carrier" => $5 }
- + end
- + if line =~ /collisions:(\d+)/
- + net_counters[cint][:tx]["collisions"] = $1
- + end
- + if line =~ /txqueuelen:(\d+)/
- + net_counters[cint][:tx]["queuelen"] = $1
- + end
- + if line =~ /RX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
- + net_counters[cint][:rx]["bytes"] = $1
- + end
- + if line =~ /TX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
- + net_counters[cint][:tx]["bytes"] = $1
- + end
- end
- popen4("arp -an") do |pid, stdin, stdout, stderr|
Add Comment
Please, Sign In to add comment