#!/bin/bash
# Settings
NASIP
="ADRES_IP_QNAP" # NAS IP AddressPASSWORD
="tu_twoje_haslo_do_usługi_snmp_na_qnap" # SNMP PasswordDOMO_IP
="ADRES_IP_DOMOTICZA" # Domoticz IP AddressDOMO_PORT
="8080" # Domoticz PortNAS_IDX
="91" # Virtual switch NAS STATUSINPUT_VOLTAGE_IDX
="50" # napięcie wejściowe na UPSOUTPUT_VOLTAGE_IDX
="51" # napięcie wyjściowe z upsBATTERY_VOLTAGE_IDX
="52" # napięcie baterii w upsUPS_TEMP_IDX
="53" # temperatura UPSBATTERY_CHARGE_IDX
="54" # naładowanie baterii# Check if NAS in online
PINGTIME
=`ping -c 1 -q $NASIP | awk -F"/" '{print $5}' | xargs`echo
$PINGTIMEif expr
"$PINGTIME" '>' 0then
#curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "On" > /dev/null
if
[ $? -eq 0 ] ; then# NAS already ON
echo
"NAS already ON"# INPUT VOLTAGE
# upsc qnapups@$NASIP:3493 > dane_ups.txt #zapis danych do pliku
# InVOLTAGE=`grep input.voltage: dane_ups.txt | cut -c16-` #wyciągnięcie z pliku napięcia wejściowego
# echo $InVOLTAGE tee voltage.txt #wyświetlenie na ekranie i zapis do pliku (samo wyśw. na ekranie to echo
InVOLTAGE
=`upsc qnapups@$NASIP:3493 | grep input.voltage: | cut -c16-` #bez zapisu do pliku wyciągnięcie napięcia wejściowego# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$INPUT_VOLTAGE_IDX&nvalue=0&svalue=$InVOLTAGE"# OUTPUT VOLTAGE
OutVOLTAGE
=`upsc qnapups@$NASIP:3493 | grep output.voltage: | cut -c17-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$OUTPUT_VOLTAGE_IDX&nvalue=0&svalue=$OutVOLTAGE"# BATTERY VOLTAGE
BatteryVOLTAGE
=`upsc qnapups@$NASIP:3493 | grep battery.voltage: | cut -c18-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$BATTERY_VOLTAGE_IDX&nvalue=0&svalue=$BatteryVOLTAGE"# UPS TEMPERATURE
UPSTemperature
=`upsc qnapups@$NASIP:3493 | grep ups.temperature: | cut -c18-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$UPS_TEMP_IDX&nvalue=0&svalue=$UPSTemperature"# BATTERY_CHARGE
BatteryCHARGE
=`upsc qnapups@$NASIP:3493 | grep battery.charge: | cut -c17-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$BATTERY_CHARGE_IDX&nvalue=0&svalue=$BatteryCHARGE"else
# NAS ON
echo
"NAS ON"# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$NAS_IDX&switchcmd=On"# INPUT VOLTAGE
InVOLTAGE
=`upsc qnapups@$NASIP:3493 | grep input.voltage: | cut -c16-`curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$INPUT_VOLTAGE_IDX&nvalue=0&svalue=$InVOLTAGE"# OUTPUT VOLTAGE
OutVOLTAGE
=`upsc qnapups@$NASIP:3493 | grep output.voltage: | cut -c17-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$OUTPUT_VOLTAGE_IDX&nvalue=0&svalue=$OutVOLTAGE"# BATTERY VOLTAGE
BatteryVOLTAGE
=`upsc qnapups@$NASIP:3493 | grep battery.voltage: | cut -c18-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$BATTERY_VOLTAGE_IDX&nvalue=0&svalue=$BatteryVOLTAGE"# UPS TEMPERATURE
UPSTemperature
=`upsc qnapups@$NASIP:3493 | grep ups.temperature: | cut -c18-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$UPS_TEMP_IDX&nvalue=0&svalue=$UPSTemperature"# BATTERY_CHARGE
BatteryCHARGE
=`upsc qnapups@$NASIP:3493 | grep battery.charge: | cut -c17-`# Send data
curl
-s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$BATTERY_CHARGE_IDX&nvalue=0&svalue=$BatteryCHARGE"fi
else
#curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep"Status" | grep "Off" > /dev/null
# NAS uitgeschakeld
if
[ $? -eq 0 ] ; thenecho
"NAS already OFF"exit
else
echo
"NAS OFF"# Send data
#curl -s -i -H "Accept: application/json""http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$NAS_IDX&switchcmd=Off"
fi
fi