pcsensor-temper/munin-plugin/temper
2017-09-15 22:46:00 +09:00

84 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
# -*- sh -*-
# Munin plugin for TEMPer
. "${MUNIN_LIBDIR}/plugins/plugin.sh"
set -o nounset
# path to pcsensor
pcsensor=${pcsensor:-/usr/local/bin/pcsensor}
# device number
device=${device:-0}
# need calibration
# example:
# env.cdef temperature,1.0287,*,0.85,-
cdef=${cdef:-temperature}
retry=${retry:-1}
autoconf() {
echo 'no'
}
config() {
cat <<EOF
graph_title TEMPer
graph_category sensors
graph_scale no
graph_vlabel Temp C
graph_args --base 1000
EOF
"$pcsensor" | awk '$2 == '"$device"' { print $3 }' |
while read -r label
do
echo "${label}.label ${label}"
echo "${label}.cdef ${cdef}"
if [ "$label" = 'humidity' ]; then
echo "${label}.draw AREA"
echo "graph_order humidity temperature"
else
echo "${label}.draw LINE"
fi
done
}
fetch() {
local value i
i=0
while [ "$i" -le "$retry" ];
do
value=$( "$pcsensor" | awk '$2 == '"$device"' { print $4 }' )
if [ -n "$value" ];then
break
fi
i=$(( i + 1 ))
sleep 5
done
echo "temperature.value ${value}"
}
# Main
case ${1:-} in
autoconf)
autoconf
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
;;
*)
fetch
;;
esac
exit 0