Guest User

Untitled

a guest
Apr 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
  2. index 7501b0b..5f6820b 100644
  3. --- a/lib/ohai/plugins/linux/network.rb
  4. +++ b/lib/ohai/plugins/linux/network.rb
  5. @@ -32,68 +32,72 @@ end
  6.  
  7. iface = Mash.new
  8. net_counters = Mash.new
  9. +ifconfig_a = nil
  10. +
  11. popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
  12. stdin.close
  13. - cint = nil
  14. - stdout.each do |line|
  15. - tmp_addr = nil
  16. - if line =~ /^([0-9a-zA-Z\.\:\-]+)\s+/
  17. - cint = $1
  18. - iface[cint] = Mash.new
  19. - if cint =~ /^(\w+)(\d+.*)/
  20. - iface[cint][:type] = $1
  21. - iface[cint][:number] = $2
  22. - end
  23. - end
  24. - if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/
  25. - iface[cint][:encapsulation] = encaps_lookup($1)
  26. - end
  27. - if line =~ /HWaddr (.+?)\s/
  28. - iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
  29. - iface[cint][:addresses][$1] = { "family" => "lladdr" }
  30. - end
  31. - if line =~ /inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  32. - iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
  33. - iface[cint][:addresses][$1] = { "family" => "inet" }
  34. - tmp_addr = $1
  35. - end
  36. - if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/
  37. - iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
  38. - iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) }
  39. - end
  40. - if line =~ /Bcast:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  41. - iface[cint][:addresses][tmp_addr]["broadcast"] = $1
  42. - end
  43. - if line =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  44. - iface[cint][:addresses][tmp_addr]["netmask"] = $1
  45. - end
  46. - flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)\s/)
  47. - if flags.length > 1
  48. - iface[cint][:flags] = flags.flatten
  49. - end
  50. - if line =~ /MTU:(\d+)/
  51. - iface[cint][:mtu] = $1
  52. - end
  53. - if line =~ /RX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) frame:(\d+)/
  54. - net_counters[cint] = Mash.new unless net_counters[cint]
  55. - net_counters[cint][:rx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "frame" => $5 }
  56. - end
  57. - if line =~ /TX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) carrier:(\d+)/
  58. - net_counters[cint][:tx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "carrier" => $5 }
  59. - end
  60. - if line =~ /collisions:(\d+)/
  61. - net_counters[cint][:tx]["collisions"] = $1
  62. - end
  63. - if line =~ /txqueuelen:(\d+)/
  64. - net_counters[cint][:tx]["queuelen"] = $1
  65. - end
  66. - if line =~ /RX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
  67. - net_counters[cint][:rx]["bytes"] = $1
  68. - end
  69. - if line =~ /TX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
  70. - net_counters[cint][:tx]["bytes"] = $1
  71. + ifconfig_a = stdout.string
  72. +end
  73. +
  74. +cint = nil
  75. +ifconfig_a.split("\n").each do |line|
  76. + tmp_addr = nil
  77. + if line =~ /^([0-9a-zA-Z\.\:\-]+)\s+/
  78. + cint = $1
  79. + iface[cint] = Mash.new
  80. + if cint =~ /^(\w+)(\d+.*)/
  81. + iface[cint][:type] = $1
  82. + iface[cint][:number] = $2
  83. end
  84. end
  85. + if line =~ /Link encap:(Local Loopback)/ || line =~ /Link encap:(.+?)\s/
  86. + iface[cint][:encapsulation] = encaps_lookup($1)
  87. + end
  88. + if line =~ /HWaddr (.+?)\s/
  89. + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
  90. + iface[cint][:addresses][$1] = { "family" => "lladdr" }
  91. + end
  92. + if line =~ /inet addr:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  93. + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
  94. + iface[cint][:addresses][$1] = { "family" => "inet" }
  95. + tmp_addr = $1
  96. + end
  97. + if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/
  98. + iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
  99. + iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) }
  100. + end
  101. + if line =~ /Bcast:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  102. + iface[cint][:addresses][tmp_addr]["broadcast"] = $1
  103. + end
  104. + if line =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
  105. + iface[cint][:addresses][tmp_addr]["netmask"] = $1
  106. + end
  107. + flags = line.scan(/(UP|BROADCAST|DEBUG|LOOPBACK|POINTTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC)\s/)
  108. + if flags.length > 1
  109. + iface[cint][:flags] = flags.flatten
  110. + end
  111. + if line =~ /MTU:(\d+)/
  112. + iface[cint][:mtu] = $1
  113. + end
  114. + if line =~ /RX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) frame:(\d+)/
  115. + net_counters[cint] = Mash.new unless net_counters[cint]
  116. + net_counters[cint][:rx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "frame" => $5 }
  117. + end
  118. + if line =~ /TX packets:(\d+) errors:(\d+) dropped:(\d+) overruns:(\d+) carrier:(\d+)/
  119. + net_counters[cint][:tx] = { "packets" => $1, "errors" => $2, "drop" => $3, "overrun" => $4, "carrier" => $5 }
  120. + end
  121. + if line =~ /collisions:(\d+)/
  122. + net_counters[cint][:tx]["collisions"] = $1
  123. + end
  124. + if line =~ /txqueuelen:(\d+)/
  125. + net_counters[cint][:tx]["queuelen"] = $1
  126. + end
  127. + if line =~ /RX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
  128. + net_counters[cint][:rx]["bytes"] = $1
  129. + end
  130. + if line =~ /TX bytes:(\d+) \((\d+?\.\d+ .+?)\)/
  131. + net_counters[cint][:tx]["bytes"] = $1
  132. + end
  133. end
  134.  
  135. popen4("arp -an") do |pid, stdin, stdout, stderr|
Add Comment
Please, Sign In to add comment