Created
June 26, 2014 14:11
-
-
Save ohadlevy/ccaec01914c2faca308c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'facter/util/ip' | |
Facter::Util::IP.get_interfaces.each do |interface| | |
Facter.debug("Running ethtool on interface #{interface}") | |
output = (Facter::Util::Resolution.exec("ethtool #{interface} 2>/dev/null")) | |
attributes = {} | |
output.each_line do |line| | |
next if line.nil? or line == "" | |
case line.strip | |
when /Speed: (.*)Mb/ | |
attributes[:speed] = $1 | |
when /Duplex: (.*)/ | |
attributes[:duplex] = $1.downcase | |
when /Port: (.*)/ | |
attributes[:port] = $1 | |
when /Auto-negotiation: (.*)/ | |
attributes[:auto_negotitation] = $1 == 'on' | |
when /^Wake-on: (.*)/ | |
attributes[:wol] = $1.include?('g') | |
when /Link detected: (.*)/ | |
attributes[:link] = $1 == 'yes' | |
end | |
end | |
if attributes.keys.empty? | |
Facter.debug("Running ethtool on #{interface} didn't give any information") | |
end | |
attributes.each do |fact, value| | |
Facter.add("#{fact}_#{Facter::Util::IP.alphafy(interface)}") do | |
confine :kernel => "Linux" | |
setcode do | |
value | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment