Commit c3fcf604 by Curt Dennis

Added JSON parsing from Cyber Power Panel to replace the previous cpupssmon.sh script

1 parent 60417496
Showing with 62 additions and 6 deletions
......@@ -16,21 +16,21 @@ get_ups_info () {
#-- Synology NAS --
#UPS Battery Voltage
syno_battvoltage=`snmpget -v 2c -c public 10.0.0.14 1.3.6.1.4.1.6574.4.3.2.1.0 -Ov`
#UPS Battery Charge
#UPS Battery Charge
syno_battcharge=`snmpget -v 2c -c public 10.0.0.14 1.3.6.1.4.1.6574.4.3.1.1.0 -Ov`
#UPS Load
#UPS Load
syno_battload=`snmpget -v 2c -c public 10.0.0.14 1.3.6.1.4.1.6574.4.2.12.1.0 -Ov`
#UPS Input Voltage
syno_inputvoltage=`snmpget -v 2c -c public 10.0.0.14 1.3.6.1.4.1.6574.4.4.1.1.0 -Ov`
#UPS Runtime
#UPS Runtime
syno_runtime=`snmpget -v 2c -c public 10.0.0.14 1.3.6.1.4.1.6574.4.3.6.1.0 -Ov`
syno_battvoltage=$(echo $syno_battvoltage | cut -c 16-)
syno_battcharge=$(echo $syno_battcharge | cut -c 16-)
syno_battload=$(echo $syno_battload | cut -c 16-)
syno_inputvoltage=$(echo $syno_inputvoltage | cut -c 16-)
syno_runtime=$(echo $syno_runtime | cut -c 10-)
syno_battvoltage=$(printf "%.0f" $syno_battvoltage)
syno_battcharge=$(printf "%.0f" $syno_battcharge)
syno_battload=$(printf "%.0f" $syno_battload)
......@@ -48,6 +48,33 @@ get_ups_info () {
}
get_ups_info_cpp() {
#-- Cyber Power Panel --
#Pull data from the Cyber Power Panel. Replace with your own IP.
cpp_json_data=$(curl http://10.0.0.60:3052/agent/ppbe.js/init_status.js)
#input voltage
cpp_involts=$(echo $cpp_json_data | grep -oP '(?<="voltage":")[^."]*' | head -1)
#battery voltage
cpp_battvolts=$(echo $cpp_json_data | grep -oP '(?<="voltage":")[^."]*' | tail -1)
#Load(Watts)
cpp_loadwatt=$(echo $cpp_json_data | grep -oP '(?<="watt":)[^,]*' | head -1)
#Capacity %
cpp_capacity=$(echo $cpp_json_data | grep -oP '(?<="capacity":)[^,]*' | head -1)
#Runtime
runtimeHour=$(echo $cpp_json_data | grep -oP '(?<="runtimeHour":)[^,]*' | head -1)
runtimeMinute=$(echo $cpp_json_data | grep -oP '(?<="runtimeMinute":)[^,]*' | head -1)
cpp_runtime=$(($runtimeHour*60*60+$runtimeMinute*60))
#Load %
cpp_loadpercent=$(echo $cpp_json_data | grep -oP '(?<="load":)[^,]*' | head -1)
}
print_data () {
echo "Synology UPS Battery Voltage: $syno_battvoltage"
echo "Synology UPS Battery Charge: $syno_battcharge"
......@@ -56,6 +83,15 @@ print_data () {
echo "Synology UPS Runtime: $syno_runtime"
}
print_data_cpp() {
echo "CPP UPS Battery Voltage: $cpp_battvolts"
echo "CPP UPS Battery Charge: $cpp_capacity"
echo "CPP UPS Load: $cpp_loadpercent"
echo "CPP UPS Load(Watts): $cpp_loadwatt"
echo "CPP UPS Input Voltage: $cpp_involts"
echo "CPP UPS Runtime: $cpp_runtime"
}
write_data () {
#Write the data to the database
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=synology,sensor=battvoltage value=$syno_battvoltage"
......@@ -65,13 +101,24 @@ write_data () {
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=synology,sensor=runtime value=$syno_runtime"
}
write_data_cpp() {
#Finally we can write it to the database
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battvoltage denhost1.value=$cpp_battvolts"
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battcharge denhost1.value=$cpp_capacity"
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battload denhost1.value=$cpp_loadpercent"
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=battloadwatt denhost1.value=$cpp_loadwatt"
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=inputvoltage denhost1.value=$cpp_involts"
curl -i -XPOST 'http://localhost:8086/write?db=home' --data-binary "ups_data,host=host1,sensor=runtime denhost1.value=$cpp_runtime"
}
#Prepare to start the loop and warn the user
echo "Press [CTRL+C] to stop..."
while :
do
get_ups_info
get_ups_info_cpp
if [[ $syno_battvoltage -le 0 || $syno_battcharge -le 0 || $syno_battload -le 0 || $syno_inputvoltage -le 0 || $syno_runtime -le 0 ]];
then
echo "Skip this datapoint - something went wrong with the read"
......@@ -82,6 +129,15 @@ do
write_data
fi
if [[ $cpp_battvolts -le 0 || $cpp_capacity -le 0 || $cpp_loadpercent -le 0 || $cpp_involts -le 0 || $cpp_runtime -le 0 ]];
then
echo "Skip this datapoint - something went wrong with the read"
else
#Output console data for future reference
print_data_cpp
write_data_cpp
fi
#Sleep between readings
sleep "$sleeptime"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!