Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created shelly__power, bugfix snmp__cyberpower #1446

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions plugins/shelly/shelly__power
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/bash

: << =cut

=head1 NAME

Power-Monitor using Shelly 3EM devices.

=head1 CONFIGURATION

Requires 'curl' and 'jq'.

=head1 AUTHOR

Kai Boenke

=head1 LICENSE

Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)

=back

=cut


#####
# Check prerequisites
###
if ! command -v "curl" > /dev/null 2>&1; then
echo "curl is not installed or not in PATH." >&2
exit -1
fi
if ! command -v "jq" > /dev/null 2>&1; then
echo "jq is not installed or not in PATH." >&2
exit -1
fi

#####
# Configuration
###
PLUGIN_NAME=${0##*/}
HOST_NAME=$(echo "$PLUGIN_NAME" | cut -d'_' -f2)

BASE_URL="http://${HOST_NAME}/emeter"
declare -A ENDPOINTS=(
["sensor_a"]="0/3em_data"
["sensor_b"]="1/3em_data"
["sensor_c"]="2/3em_data"
)
declare -A LABELS=(
["sensor_a"]="Phase A"
["sensor_b"]="Phase B"
["sensor_c"]="Phase C"
)

#####
# Handle Munin-Config
##
case $1 in
config)
# Power Consumption
echo "multigraph shelly_power"
echo "graph_title Power Consumption"
echo "graph_vlabel watt [w]"
echo "graph_category sensors"
echo "graph_info Current power consumption for each phase."
for sensor in "${!LABELS[@]}"; do
echo "${sensor}_w.label ${LABELS[$sensor]}"
echo "${sensor}_w.warning 800"
echo "${sensor}_w.critical 1000"
done
# Voltages
echo "multigraph shelly_voltage"
echo "graph_title Voltages"
echo "graph_vlabel volt [V]"
echo "graph_category sensors"
echo "graph_info Current voltages for each phase."
for sensor in "${!LABELS[@]}"; do
echo "${sensor}_v.label ${LABELS[$sensor]}"
echo "${sensor}_v.warning 220:240"
echo "${sensor}_v.critical 210:250"
done
# Power Factor
echo "multigraph shelly_pf"
echo "graph_title Power Factor"
echo "graph_vlabel I/V"
echo "graph_category sensors"
echo "graph_info Current power factor for each phase."
for sensor in "${!LABELS[@]}"; do
echo "${sensor}_pf.label ${LABELS[$sensor]}"
done
exit 0;;
esac

#####
# Measurements
###

echo "multigraph shelly_power"
for sensor in "${!ENDPOINTS[@]}"; do
url="${BASE_URL}/${ENDPOINTS[$sensor]}"
response=$(curl -s "$url")
if [ $? -eq 0 ]; then
power=$(echo "$response" | jq -r '.power')
echo "${sensor}_w.value ${power}"
else
echo "${sensor}_w.value U"
fi
done

echo "multigraph shelly_voltage"
for sensor in "${!ENDPOINTS[@]}"; do
url="${BASE_URL}/${ENDPOINTS[$sensor]}"
response=$(curl -s "$url")
if [ $? -eq 0 ]; then
power=$(echo "$response" | jq -r '.voltage')
echo "${sensor}_v.value ${power}"
else
echo "${sensor}_v.value U"
fi
done

echo "multigraph shelly_pf"
for sensor in "${!ENDPOINTS[@]}"; do
url="${BASE_URL}/${ENDPOINTS[$sensor]}"
response=$(curl -s "$url")
if [ $? -eq 0 ]; then
power=$(echo "$response" | jq -r '.pf')
echo "${sensor}_pf.value ${power}"
else
echo "${sensor}_pf.value U"
fi
done
2 changes: 1 addition & 1 deletion plugins/snmp/snmp__cyberpower
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ sub oidExists {
my $oid = $_[0];
my $val = $session->get_single($oid);

if(!length $val || $val eq 'noSuchInstance' || $val eq 'U'){
if(!length $val || $val eq 'noSuchInstance' || $val eq 'U' || $val eq 'NULL'){
return(0);
}else{
return(1);
Expand Down