Add better system identification to custom fact

This commit is contained in:
waal70
2025-09-02 12:08:25 +02:00
parent f606b8573d
commit c81a592635

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
hostname=$(hostname); 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); architecture=$(arch);
processor_model=$(cat /proc/cpuinfo | grep -E '^(model name|Model)\s*:' | sort -u | cut -d ':' -f2- | cut -d ' ' -f2-); 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}'); 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=$? cat /proc/cpuinfo | grep -q 'Intel'; rc=$?
systemtype=$(if [[ $rc -eq 0 ]]; then echo "Intel"; else echo "$systemtype"; fi) 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"}'\ if [ -f /sys/devices/virtual/dmi/id/product_name ]; then
"$systemtype" "$hostname" "$operating_system" "$architecture" "$processor_model" "$memory" "$system_main_ip" 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"