summaryrefslogtreecommitdiffstats
path: root/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-21 13:19:06 +0100
committerSimon Rettberg2015-12-21 13:19:06 +0100
commit44a593c07c8ca2bf05e5e3e293cfd4e7512d9e73 (patch)
treee993f7b141ff3b1b97473744e5bcb32838574a89 /remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats
parent[rfs-stage31] Fix download function timeout handling (diff)
downloadtm-scripts-44a593c07c8ca2bf05e5e3e293cfd4e7512d9e73.tar.gz
tm-scripts-44a593c07c8ca2bf05e5e3e293cfd4e7512d9e73.tar.xz
tm-scripts-44a593c07c8ca2bf05e5e3e293cfd4e7512d9e73.zip
[hardware-stats] Include smartctl, add model name
Diffstat (limited to 'remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats')
-rwxr-xr-xremote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats41
1 files changed, 35 insertions, 6 deletions
diff --git a/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats b/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats
index 2d0a30c7..6a3829e5 100755
--- a/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats
+++ b/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats
@@ -1,5 +1,6 @@
#!/bin/bash
# Use bash since ash can only do math on 32bit numbers, which is not sufficient for ID44 calculations
+# also for negative length to ${x:0:-1}
# This script gathers information about the hardware and configuration and reports it back to the server
@@ -99,10 +100,13 @@ ID44=$(( $ID44 / 1058576 )) # we'd rather underreport
# 9) check smart values
BADSECTORS=0
if which smartctl; then
+ ALLSMART=$(mktemp)
FILE=$(mktemp)
[ -z "$FILE" ] && FILE="/tmp/smartctl.$$.$RANDOM.$RANDOM"
- for dev in /dev/sd?; do
- smartctl -H -A -f "brief" "$dev" > "$FILE" || continue
+ for dev in $(fdisk -l | grep -o '^Disk /dev/\S*:' | cut -c 6-); do
+ dev=${dev:0:-1}
+ smartctl -i -H -A -f "brief" "$dev" > "$FILE" || continue
+ cat "$FILE" >> "$ALLSMART"
# parse
OVERALL=$(grep -o "test result: .*$" "$FILE" | cut -c 14-)
[ "x$OVERALL" = "xPASSED" ] && OVERALL=""
@@ -120,10 +124,24 @@ if which smartctl; then
rm -f -- "$FILE"
fi
+# A) Read system model and manufacturer
+MODEL=$(dmidecode -s system-product-name)
+case "$MODEL" in
+ |System Product Name|*be filled*)
+ MODEL="Unknown"
+ ;;
+ *)
+ MANUF=$(dmidecode -s system-manufacturer)
+ ;;
+esac
+if [ -n "$MANUF" ]; then
+ MODEL="$MODEL ($MANUF)"
+fi
+
# n) Dump raw data to a file
DATAFILE=$(mktemp)
[ -z "$DATAFILE" ] && DATAFILE="/root/power-stats.$$"
-cat > "$DATAFILE" <<EOF
+cat > "$DATAFILE" <<-EOF
############################### CPU #####################################
Sockets: $(grep '^physical id' /proc/cpuinfo | sort -u | wc -l)
Real cores: $CPUCORES
@@ -131,21 +149,32 @@ Virtual cores: $(grep '^processor' /proc/cpuinfo | sort -u | wc -l)
######################## Partition tables ###############################
EOF
fdisk -l >> "$DATAFILE"
-cat >> "$DATAFILE" <<EOF
+cat >> "$DATAFILE" <<-EOF
############################ PCI ID #####################################
EOF
lspci -n -m >> "$DATAFILE"
-cat >> "$DATAFILE" <<EOF
+cat >> "$DATAFILE" <<-EOF
########################## dmidecode ####################################
EOF
dmidecode >> "$DATAFILE"
+if [ -n "$ALLSMART" ] && [ -s "$ALLSMART" ]; then
+ cat >> "$DATAFILE" <<-EOF
+ ########################### smartctl ####################################
+ EOF
+ cat "$ALLSMART" >> "$DATAFILE"
+fi
+cat >> "$DATAFILE" <<-EOF
+#########################
+EOF
+
+[ -n "$ALLSMART" ] && rm -f -- "$ALLSMART"
# Fire away
for DELAY in 1 1 0; do
if curl --data-urlencode "type=~poweron" --data-urlencode "uuid=$UUID" --data-urlencode "macaddr=$MAC" \
--data-urlencode "uptime=$UPTIME" --data-urlencode "realcores=$CPUCORES" --data-urlencode "mbram=$RAM" \
--data-urlencode "kvmstate=$VT" --data-urlencode "cpumodel=$CPUMODEL" --data-urlencode "id44mb=$ID44" \
- --data-urlencode "badsectors=$BADSECTORS" \
+ --data-urlencode "badsectors=$BADSECTORS" --data-urlencode "systemmodel=$MODEL" \
--data-urlencode "data@$DATAFILE" "$SLX_REMOTE_LOG" | grep -q "RESULT=0"; then
rm -f -- "$DATAFILE"
echo "$UUID" > "/run/system-uuid"