Skip to content

Instantly share code, notes, and snippets.

@mheffner
Created February 15, 2015 20:14
Show Gist options
  • Save mheffner/15e44298b65244aee611 to your computer and use it in GitHub Desktop.
Save mheffner/15e44298b65244aee611 to your computer and use it in GitHub Desktop.
USB thermometer to Librato measure
#!/bin/bash
# Submit USB thermometer temperature to Librato
#
# Use with: https://github.com/petechap/usb-thermometer
#
#
# FILL OUT:
#
EMAIL=""
TOKEN=""
SOURCE="basement"
WD="/home/mheffner/usb-thermometer"
METRIC="env.temperature"
METRIC_FAILED="env.failed"
function submit_failed()
{
curl -s -u "$EMAIL:$TOKEN" \
https://metrics-api.librato.com/v1/metrics \
-X POST \
-d 'gauges[0][name]='"$METRIC_FAILED"'&gauges[0][source]='"$SOURCE"'&gauges[0][value]=1'
}
function submit()
{
VAL=$1
curl -s -u "$EMAIL:$TOKEN" \
https://metrics-api.librato.com/v1/metrics \
-X POST \
-d 'gauges[0][name]='"$METRIC"'&gauges[0][source]='"$SOURCE"'&gauges[0][value]='"$VAL"
}
TMP=`mktemp`
sudo ${WD}/pcsensor > $TMP 2> $HOME/fail_log
if [ $? -ne 0 ]; then
submit_failed
rm $TMP
exit 1
fi
TEMP=`cat $TMP | awk '{print $4}' | sed 's/F$//'`
rm $TMP
if [ -z "$TEMP" ]; then
submit_failed
exit 1
fi
submit $TEMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment