# cat /usr/sbin/smartctl-influx.sh #!/bin/bash lsblk | grep disk | while read device _ ; do /usr/sbin/smartctl -a /dev/$device \ | awk -v timestamp=$(date +%s"000000000") ' function after(x) { out="" for (i=x; i<=NF; i++) out=out" "$i return out } BEGIN { Model="none" Serial="none" } /^Device Model:/ { Model=after(3) sub(/^[ \t\r\n]+/, "", Model) gsub(" ", "_", Model) } /^Serial Number:/ { Serial=after(3) sub(/^[ \t\r\n]+/, "", Serial) gsub(" ", "_", Serial) } /^\s*[0-9]+ [a-zA-Z_-]{5,}/ { if ( $10 ~ /^[0-9]+$/ ) Values[$1]=$10 } END { if (Serial != "none") { printf("disk,serial=" Serial ",model=" Model " ") first=1 for (value in Values) { if ( ! first) printf(",") first=0 printf(value"="Values[value]) } printf(" " timestamp "\n") } } ' \ | while read data ; do curl --header "Authorization: Token ..." -X POST 'http://influxdb/write?db=smartctl' --data-binary "$data" done done