mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
Fix issues detected in munin-monitoring!PR 1312
Consistent tabbing perldoc style comment detect curl and jq prereqs shellcheck linting error handling jq parsing
This commit is contained in:
parent
cdd731d0ae
commit
33b1b80361
1 changed files with 64 additions and 50 deletions
|
@ -42,20 +42,46 @@ GPLv2 or later
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
cached_curl=none
|
||||||
|
# runs curl on "Status $1", and parses through jq -c "$2", setting the value in "$res"
|
||||||
|
# Caches the curl results for when we're plotting multiple (power) values
|
||||||
|
# -- don't forget to make sure we're not being called in a subshell!
|
||||||
|
get_value() {
|
||||||
|
if [ "$cached_curl" = none ] ; then
|
||||||
|
# run curl, cache the result, and if there was an error, set value to "U"
|
||||||
|
if ! cached_curl=$( curl --max-time 5 -fsS --data-urlencode "cmnd=Status $1" "http://$DEVICE/cm" ) ; then
|
||||||
|
cached_curl='{}'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
res=$( echo "$cached_curl" | jq -c "$2" )
|
||||||
|
if [ "$res" = null ] ; then
|
||||||
|
res=U
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
DEVICE=$(basename "$0" | cut -d_ -f2)
|
DEVICE=$(basename "$0" | cut -d_ -f2)
|
||||||
FUNCTION=$(basename "$0" | cut -d_ -f3)
|
FUNCTION=$(basename "$0" | cut -d_ -f3)
|
||||||
|
|
||||||
if [ "$1" = "autoconf" ]; then
|
if [ "$1" = "autoconf" ]; then
|
||||||
|
if ! which curl > /dev/null 2>&1 ; then
|
||||||
|
echo "no (no curl)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if ! which jq > /dev/null 2>&1 ; then
|
||||||
|
echo "no (no jq)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
echo yes && exit 0
|
echo yes && exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "suggest" ]; then
|
if [ "$1" = "suggest" ]; then
|
||||||
nodeattr -n 'tasmota&&powermon' | while read device ; do
|
nodeattr -n 'tasmota&&powermon' | while read -r device ; do
|
||||||
for i in voltage power powerfactor current energy ; do
|
for i in voltage power powerfactor current energy ; do
|
||||||
echo "${device}_${i}"
|
echo "${device}_${i}"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
nodeattr -n 'tasmota&&DS18B20temp' | while read device ; do
|
nodeattr -n 'tasmota&&DS18B20temp' | while read -r device ; do
|
||||||
for i in DS18B20temp ; do
|
for i in DS18B20temp ; do
|
||||||
echo "${device}_${i}"
|
echo "${device}_${i}"
|
||||||
done
|
done
|
||||||
|
@ -67,16 +93,14 @@ voltage() {
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
echo "graph_title Tasmota Voltage: $DEVICE"
|
echo "graph_title Tasmota Voltage: $DEVICE"
|
||||||
echo "graph_category sensors"
|
|
||||||
echo "graph_vlabel Volts"
|
echo "graph_vlabel Volts"
|
||||||
echo "graph_args --base 1000 -l 0"
|
echo "graph_args --base 1000 -l 0"
|
||||||
|
|
||||||
echo "Volts.label Volts"
|
echo "Volts.label Voltage"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
|
get_value 8 ".StatusSNS.ENERGY.Voltage"
|
||||||
volts=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Voltage' )
|
echo "Volts.value $res"
|
||||||
echo Volts.value $volts
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,16 +108,14 @@ current() {
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
echo "graph_title Tasmota Current: $DEVICE"
|
echo "graph_title Tasmota Current: $DEVICE"
|
||||||
echo "graph_category sensors"
|
|
||||||
echo "graph_vlabel Amps"
|
echo "graph_vlabel Amps"
|
||||||
echo "graph_args --base 1000 -l 0"
|
echo "graph_args --base 1000 -l 0"
|
||||||
|
|
||||||
echo "Current.label Current"
|
echo "Current.label Current"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
|
get_value 8 ".StatusSNS.ENERGY.Current"
|
||||||
current=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Current' )
|
echo "Current.value $res"
|
||||||
echo Current.value $current
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +123,6 @@ power() {
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
echo "graph_title Tasmota Power: $DEVICE"
|
echo "graph_title Tasmota Power: $DEVICE"
|
||||||
echo "graph_category sensors"
|
|
||||||
echo "graph_vlabel Watts"
|
echo "graph_vlabel Watts"
|
||||||
echo "graph_args --base 1000 -l 0"
|
echo "graph_args --base 1000 -l 0"
|
||||||
|
|
||||||
|
@ -111,10 +132,9 @@ power() {
|
||||||
echo "${i}.min 0"
|
echo "${i}.min 0"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
|
|
||||||
for i in Power ApparentPower ReactivePower ; do
|
for i in Power ApparentPower ReactivePower ; do
|
||||||
power=$( echo "$res" | jq -c '.StatusSNS.ENERGY.'$i )
|
get_value 8 ".StatusSNS.ENERGY.$i"
|
||||||
echo $i.value $power
|
echo "$i.value $res"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -123,7 +143,6 @@ powerfactor() {
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
echo "graph_title Tasmota Power factor: $DEVICE"
|
echo "graph_title Tasmota Power factor: $DEVICE"
|
||||||
echo "graph_category sensors"
|
|
||||||
echo "graph_vlabel Power Factor"
|
echo "graph_vlabel Power Factor"
|
||||||
echo "graph_args --base 1000 -l 0"
|
echo "graph_args --base 1000 -l 0"
|
||||||
|
|
||||||
|
@ -132,9 +151,8 @@ powerfactor() {
|
||||||
echo "PowerFactor.label Power Factor"
|
echo "PowerFactor.label Power Factor"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
|
get_value 8 ".StatusSNS.ENERGY.Factor"
|
||||||
powerfactor=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Factor' )
|
echo "PowerFactor.value $res"
|
||||||
echo PowerFactor.value $powerfactor
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +160,6 @@ energy() {
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
echo "graph_title Tasmota Energy: $DEVICE"
|
echo "graph_title Tasmota Energy: $DEVICE"
|
||||||
echo "graph_category sensors"
|
|
||||||
echo "graph_args --base 1000"
|
echo "graph_args --base 1000"
|
||||||
|
|
||||||
echo "graph_vlabel kWh"
|
echo "graph_vlabel kWh"
|
||||||
|
@ -151,9 +168,8 @@ energy() {
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
res=$( curl -fsS --data-urlencode "cmnd=Status 8" http://$DEVICE/cm )
|
get_value 8 ".StatusSNS.ENERGY.Total"
|
||||||
energy=$( echo "$res" | jq -c '.StatusSNS.ENERGY.Total' )
|
echo "Energy.value $res"
|
||||||
echo Energy.value $energy
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +177,6 @@ DS18B20temp() {
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
echo "graph_title Tasmota Temperature: $DEVICE"
|
echo "graph_title Tasmota Temperature: $DEVICE"
|
||||||
echo "graph_category sensors"
|
|
||||||
echo "graph_args --base 1000"
|
echo "graph_args --base 1000"
|
||||||
|
|
||||||
echo "graph_vlabel °C"
|
echo "graph_vlabel °C"
|
||||||
|
@ -171,9 +186,8 @@ DS18B20temp() {
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
res=$( curl -fsS --data-urlencode "cmnd=Status 10" http://$DEVICE/cm )
|
get_value 10 ".StatusSNS.DS18B20.Temperature"
|
||||||
energy=$( echo "$res" | jq -c '.StatusSNS.DS18B20.Temperature' )
|
echo "Temperature.value $res"
|
||||||
echo Temperature.value $energy
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue