Created
August 10, 2015 17:13
-
-
Save rothwerx/e1308d61512d7c278268 to your computer and use it in GitHub Desktop.
Bash: Collect HBA/HCA information for facter
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
#!/bin/bash | |
# Produce custom facts about HBA/HCA cards for facter | |
# This file should be executable in /etc/facter/facts.d/ | |
# Look for Mellanox, Emulex, and QLogic cards | |
varq=$(lspci | awk '/[Mm]ellanox/ { | |
printf "mellanox=%s\n", $1 } | |
/[Ee]mulex/ { | |
printf "emulex=%s\n", $1 } | |
/[Qq][Ll]ogic/ { | |
printf "qlogic=%s\n", $1 }') | |
# Convert to array | |
qarr=($varq) | |
if [ ${#qarr[@]} -eq 0 ]; then | |
exit 0 | |
fi | |
function vitalinfo() { | |
#Need to pass HBA, Address, and Counter | |
hbca=$1 | |
addy=$2 | |
counter=$3 | |
echo "hba_${hbca}${counter}_address=$addy" | |
# The gsub() are just thee to strip off the leading space | |
lspci -vv -s $addy | awk -v ctr=$counter -v hba=$hbca -F: ' | |
/Product Name/ { | |
gsub(/^ /, "", $2) | |
printf "hba_%s%d_name=%s\n", hba, ctr, $2 } | |
/Part number/ { | |
gsub(/^ /, "", $2) | |
printf "hba_%s%d_part=%s\n", hba, ctr, $2 } | |
/Serial number/ { | |
gsub(/^ /, "", $2) | |
printf "hba_%s%d_serial=%s\n",hba, ctr, $2 }' | |
} | |
counter=0 | |
for i in ${qarr[@]}; do | |
# If this is the first occurrence of a new HBA, reset counter to 0 | |
if [[ $hba != ${i%=*} ]]; then | |
counter=0 | |
fi | |
# Sprinkle some pattern-matching magic on it | |
hba=${i%=*} | |
addr=${i#*=} | |
# The idea here is to only check the first function | |
# of a PCIe card (XX:XX.0) | |
if [[ ${addr:(-1)} -eq 0 ]]; then | |
vitalinfo $hba $addr $counter | |
((counter++)) | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment