bundlewrap/bundles/smartctl/files/telegraf_plugin
2021-10-30 20:13:24 +02:00

30 lines
679 B
Bash

#!/bin/bash
for device in $(smartctl --scan | cut -d' ' -f1)
do
# POWER STATUS
if $(smartctl -n idle -n sleep -i $device | grep "Power mode" | grep -q "STANDBY")
then
active=False
else
active=True
fi
echo "smartctl,host=${node.name},device=$device active=$active $(date --utc +%s%N)"
# TEMPS
temp=$(smartctl -n idle -A --json=c $device | jq .temperature.current)
if [[ $temp == ?(-)+([0-9]) ]]
then
echo "smartctl,host=${node.name},device=$device temperature=<%text>${temp}</%text>i $(date --utc +%s%N)"
elif [[ $temp == null ]]
then
# hdd might be sleeping
continue
else
# hdd might be unsupported
continue
fi
done