Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added PCI card reporting (#158)
* Added PCI card reporting

---------

Co-authored-by: Kit Gerrits <kit@gen8.strike2.org>
  • Loading branch information
kitgerrits and Kit Gerrits committed Jun 23, 2023
1 parent f08289b commit 3229c47
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions root/usr/share/fdi/facts/pcicards.rb
@@ -0,0 +1,61 @@
# PCI Card Enumeration Script

# This is what lspci output looks like:
# [empty line]
# Slot: 01:00.0
# Class: RAID bus controller
# Vendor: LSI Logic / Symbios Logic
# Device: MegaRAID SAS-3 3108 [Invader]
# SVendor: IBM
# SDevice: Device 0454
# PhySlot: 4
# Rev: 02
# NUMANode: 0
# [empty line]
# [another section]

# Expected output:
# pci_device_0 => NetXtreme BCM5719 Gigabit Ethernet PCIe
# pci_device_1 => SFC9220 10/40G Ethernet Controller
# pci_device_2 => SFC9220 10/40G Ethernet Controller
# pci_device_4 => MegaRAID SAS-3 3108 [Invader]

require 'facter'

# Read lspci
begin
lspci_output = %x{lspci -mm -v}
rescue => e
warn "Invocation of lspci failed: #{e}"
lspci_output = ''
end

# Filter relevant data
all_devices = {}
current_element = {}
lspci_output.each_line do |line|
line.chomp!
# Newline triggers evaluation of values read earlier
if line == '' then
# Only store PCI devices that report a physical PCI slot
if current_element.has_key?('physlot') then
all_devices[current_element['physlot']] = current_element['device']
end

# Clear values, process next PCI device
current_element = {}
next
end

key, value = line.split(/:\t/, 2)
key.downcase!

current_element[key] = value
end

# Convert stored data to facts:
all_devices.each do |slot, model|
Facter.add("pci_device_#{slot}") do
setcode { model.chomp }
end
end

0 comments on commit 3229c47

Please sign in to comment.