Skip to content

Instantly share code, notes, and snippets.

@micah
Created July 17, 2020 14:53
Show Gist options
  • Save micah/3eca3203444bd2156dd24fd1db0539fb to your computer and use it in GitHub Desktop.
Save micah/3eca3203444bd2156dd24fd1db0539fb to your computer and use it in GitHub Desktop.
# This fact will spit out the e1000 devices that we know have a driver problem.
#
# There are no dependencies needed for this script, except for lspci.
case Facter.value(:operatingsystem)
when /Debian|Ubuntu/i
lspci = "/usr/bin/lspci"
when /RedHat|CentOS|Fedora|Scientific|SLES/i
lspci = "/sbin/lspci"
else
lspci = ""
end
# We can't do this if we don't know the location of lspci
if !lspci.empty? and FileTest.exists?(lspci)
# Create a hash of ALL PCI devices, the key is the PCI slot ID.
# { SLOT_ID => { ATTRIBUTE => VALUE }, ... }
slot=""
# after the following loop, devices will contain ALL PCI devices and the info returned from lspci
devices = {}
%x{#{lspci} -v -mm -D -n}.each_line do |line|
if not line =~ /^$/ # We don't need to parse empty lines
splitted = line.split(/\t/)
# lspci has a nice syntax:
# ATTRIBUTE:\tVALUE
# We use this to fill our hash
if splitted[0] =~ /^Slot:$/
slot=splitted[1].chomp
devices[slot] = {}
else
# The chop is needed to strip the ':' from the string
devices[slot][splitted[0].chop] = splitted[1].chomp
end
end
end
device = ""
devices.each_key do |a|
case devices[a].fetch("Vendor")
when /^8086/
if devices[a].fetch("Device") =~ /(^153a|^1096)/
device = "#{device}," + Dir.entries("/sys/bus/pci/devices/#{a}/net").select {|f| !File.directory? f}[0]
end
end
end
Facter.add(:e1000problems) do
setcode do
Facter.value(:device)
device.split(',')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment