Skip to content

Instantly share code, notes, and snippets.

@scrathe
Last active March 23, 2020 01:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scrathe/2a2cedf4bc79ac5a0facb3ebdf82aaef to your computer and use it in GitHub Desktop.
#!/bin/bash
# what is this? poll your UPS using "upsc" and store values using InfluxDB for use with Grafana
# unRAID UPS plugin; https://forums.unraid.net/topic/60217-plugin-nut-v2-network-ups-tools/
# unRAID CA User Scripts; plugin https://forums.unraid.net/topic/48286-plugin-ca-user-scripts/
# unRAID User Scripts; add script, custom schedule = */1 * * * *
command="upsc ups"
influxdb="ups,host=Tower"
curlargs="-s --output /dev/null -i -XPOST --data-binary"
url="http://10.0.20.20:8086/write?db=telegraf"
array=(
battery.charge
battery.runtime
device.model
output.voltage
ups.load
ups.realpower.nominal
)
for i in "${array[@]}"
do
output=$($command $i)
data="$influxdb $i=$output"
# echo "curlcmd=(curl $curlargs "$data" "$url")"
curlcmd=$(curl $curlargs "$data" "$url")
if [[ $i = "ups.realpower.nominal" ]]; then
ups_realpower_nominal="$output"
fi
if [[ $i = "ups.load" ]]; then
ups_load="$output"
fi
done
ups_realpower=$(($ups_load * $ups_realpower_nominal / 100))
data="$influxdb ups.realpower=$ups_realpower"
# echo "curlcmd=(curl $curlargs "$data" "$url")"
curlcmd=$(curl $curlargs "$data" "$url")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment