Add better system identification to custom fact
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
hostname=$(hostname);
|
||||
operating_system=$(hostnamectl | grep "Operating System" | cut -d ' ' -f3-);
|
||||
operating_system=$(hostnamectl | grep "Operating System" | cut -d ':' -f2- | sed 's/^[ \t]*//');
|
||||
architecture=$(arch);
|
||||
processor_model=$(cat /proc/cpuinfo | grep -E '^(model name|Model)\s*:' | sort -u | cut -d ':' -f2- | cut -d ' ' -f2-);
|
||||
memory=$(free -h --si --total | grep -oP '^Total:\s+([\d,]+[.]*[\d]*)[ ]*([A-Za-z]+)' | awk '{print $2}');
|
||||
@@ -13,5 +13,25 @@ systemtype=$(if [[ $rc -eq 0 ]]; then echo "Raspberry"; else echo "Generic"; fi)
|
||||
cat /proc/cpuinfo | grep -q 'Intel'; rc=$?
|
||||
systemtype=$(if [[ $rc -eq 0 ]]; then echo "Intel"; else echo "$systemtype"; fi)
|
||||
|
||||
printf '{"systemtype":"%s","hostname":"%s","operating_system":"%s","architecture":"%s","processor_name":"%s","memory":"%s","system_main_ip":"%s"}'\
|
||||
"$systemtype" "$hostname" "$operating_system" "$architecture" "$processor_model" "$memory" "$system_main_ip"
|
||||
if [ -f /sys/devices/virtual/dmi/id/product_name ]; then
|
||||
productname=$(cat /sys/devices/virtual/dmi/id/product_name)
|
||||
elif [ -d /sys/devices/platform/CLK ]; then
|
||||
productname="CloudKey"
|
||||
elif [[ "$systemtype" == "Raspberry" ]]; then
|
||||
productname=$processor_model
|
||||
else
|
||||
productname="Unknown"
|
||||
fi
|
||||
|
||||
if [ -f /sys/devices/virtual/dmi/id/board_vendor ]; then
|
||||
manufacturer=$(cat /sys/devices/virtual/dmi/id/board_vendor | awk '{print $1}')
|
||||
elif [[ "$systemtype" == "Raspberry" ]]; then
|
||||
manufacturer="Raspberry Pi Foundation"
|
||||
elif [[ "$productname" == "CloudKey" ]]; then
|
||||
manufacturer="Ubiquiti"
|
||||
else
|
||||
manufacturer="Unknown"
|
||||
fi
|
||||
|
||||
printf '{"systemtype":"%s","manufacturer":"%s","productname":"%s","hostname":"%s","operating_system":"%s","architecture":"%s","processor_name":"%s","memory":"%s","system_main_ip":"%s"}'\
|
||||
"$systemtype" "$manufacturer" "$productname" "$hostname" "$operating_system" "$architecture" "$processor_model" "$memory" "$system_main_ip"
|
||||
Reference in New Issue
Block a user