Commit c3fcf604 authored by Curt Dennis's avatar Curt Dennis
Browse files

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

parent 60417496
...@@ -16,21 +16,21 @@ get_ups_info () { ...@@ -16,21 +16,21 @@ get_ups_info () {
#-- Synology NAS -- #-- Synology NAS --
#UPS Battery Voltage #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` 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` 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` 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 #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` 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_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_battvoltage=$(echo $syno_battvoltage | cut -c 16-)
syno_battcharge=$(echo $syno_battcharge | cut -c 16-) syno_battcharge=$(echo $syno_battcharge | cut -c 16-)
syno_battload=$(echo $syno_battload | cut -c 16-) syno_battload=$(echo $syno_battload | cut -c 16-)
syno_inputvoltage=$(echo $syno_inputvoltage | cut -c 16-) syno_inputvoltage=$(echo $syno_inputvoltage | cut -c 16-)
syno_runtime=$(echo $syno_runtime | cut -c 10-) syno_runtime=$(echo $syno_runtime | cut -c 10-)
syno_battvoltage=$(printf "%.0f" $syno_battvoltage) syno_battvoltage=$(printf "%.0f" $syno_battvoltage)
syno_battcharge=$(printf "%.0f" $syno_battcharge) syno_battcharge=$(printf "%.0f" $syno_battcharge)
syno_battload=$(printf "%.0f" $syno_battload) syno_battload=$(printf "%.0f" $syno_battload)
...@@ -48,6 +48,33 @@ get_ups_info () { ...@@ -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 () { print_data () {
echo "Synology UPS Battery Voltage: $syno_battvoltage" echo "Synology UPS Battery Voltage: $syno_battvoltage"
echo "Synology UPS Battery Charge: $syno_battcharge" echo "Synology UPS Battery Charge: $syno_battcharge"
...@@ -56,6 +83,15 @@ print_data () { ...@@ -56,6 +83,15 @@ print_data () {
echo "Synology UPS Runtime: $syno_runtime" 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_data () {
#Write the data to the database #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" 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 () { ...@@ -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" 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 #Prepare to start the loop and warn the user
echo "Press [CTRL+C] to stop..." echo "Press [CTRL+C] to stop..."
while : while :
do do
get_ups_info 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 ]]; if [[ $syno_battvoltage -le 0 || $syno_battcharge -le 0 || $syno_battload -le 0 || $syno_inputvoltage -le 0 || $syno_runtime -le 0 ]];
then then
echo "Skip this datapoint - something went wrong with the read" echo "Skip this datapoint - something went wrong with the read"
...@@ -82,6 +129,15 @@ do ...@@ -82,6 +129,15 @@ do
write_data write_data
fi 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 between readings
sleep "$sleeptime" sleep "$sleeptime"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment