Created
December 2, 2011 21:42
-
-
Save crazed/1424959 to your computer and use it in GitHub Desktop.
useful facter plugins
This file contains 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
if File::exists?("/sbin/ip") | |
Facter.add('gateway') do | |
setcode do | |
`/sbin/ip route show`.match(/^default.*/)[0].match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)[0] | |
end | |
end | |
end |
This file contains 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
if File.exists?('/usr/bin/ipmitool') | |
Facter.add('bmc_ip_address') do | |
setcode do | |
begin | |
Timeout::timeout(3) { `ipmitool lan print 1 | grep 'IP Address ' | cut -d: -f2 | sed 's/ //g'` } | |
rescue | |
nil | |
end | |
end | |
end | |
end |
This file contains 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
if File.exists?('/usr/sbin/lldpctl') | |
lldp = Hash.new | |
`lldpctl -f keyvalue`.split(/\n/).each do |line| | |
key, value = line.split(/=/) | |
lldp[key] ||= Array.new | |
lldp[key] << value | |
lldp[key].uniq! | |
end | |
# things we care about from lldp | |
lldp_keys = ['chassis.name', 'port.descr', 'vlan.vlan-id', 'vlan'] | |
Facter.value('interfaces').split(/,/).each do |interface| | |
lldp_keys.each do |lldp_key| | |
fact_string = "lldp.#{interface}.#{lldp_key}" | |
if lldp.has_key?(fact_string) | |
Facter.add(fact_string.gsub('.', '_')) do | |
setcode do | |
lldp[fact_string].join(',') | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment