Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
domoticz
#3
Skryptem. Utworzyłem plik o nazwie lk.sh w RPi w katalogu /home/pi/domoticz/scripts a wśrodku
--CUT----

#!/bin/bash

# Settings

LKIP="192.168.0.109" # NLK IP Address
PASSWORD="public" # SNMP Password
DOMO_IP="192.168.0.104" # Domoticz IP Address
DOMO_PORT="8080" # Domoticz Port
LK_IDX="3" # Virtual switch NAS STATUS
CPU_TEMP_IDX="14" # Virtual temerature sensor IDX BOARD
ZASILANIE_IDX="12" # Napiecie zasilania
DS1_TEMP_IDX="15" # Virtual temerature sensor IDX HD2
HD3_TEMP_IDX="7" # Virtual temerature sensor IDX HD3
HD4_TEMP_IDX="8" # Virtual temerature sensor IDX HD4
HD_REMAIN_IDX="11" # Virtual temerature sensor IDX HD REMAIN

# Check if LK in online

PINGTIME=`ping -c 1 -q $LKIP | awk -F"/" '{print $5}' | xargs`

echo $PINGTIME
if expr "$PINGTIME" '>' 0
then
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$LK_IDX" | grep "Status" | grep "On" > /dev/null

if [ $? -eq 0 ] ; then
# NAS already ON
echo "NAS already ON"

# Temprature Board
CPUtemp=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.17095.4.1.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"

# Napiecie zasilania
Volt=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.17095.4.2.0 | cut -c 2-4`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$ZASILANIE_IDX&nvalue=0&svalue=$Volt"

# Temperature DS
DStemp1=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.17095.5.1.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DS1_TEMP_IDX&nvalue=0&svalue=$DStemp1"


# Temperature HD3
#HDtemp3=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.24681.1.2.11.1.3.3 | cut -c 2-3`
# Send data
#curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD3_TEMP_IDX&nvalue=0&svalue=$HDtemp3"

# Temperature HD4
#HDtemp4=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.24681.1.2.11.1.3.4 | cut -c 2-3`
# Send data
#curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD4_TEMP_IDX&nvalue=0&svalue=$HDtemp4"


# Remaining HD size
#size=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.24681.1.2.17.1.5.1 | cut -c 2-7`
# Send data
#curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD_REMAIN_IDX&nvalue=0&svalue=$size"
else
# NAS ON
echo "LK ON"
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$LK_IDX&switchcmd=On"

# Temprature Board
CPUtemp=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.17095.4.1.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"

# Napiecie zasilania
Volt=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.17095.4.2.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$ZASILANIE_IDX&nvalue=0&svalue=$Volt"

# Temperature DS1
DStemp1=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.17095.5.1.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DS1_TEMP_IDX&nvalue=0&svalue=$DStemp1"

# Temperature HD3
#HDtemp3=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.24681.1.2.11.1.3.3 | cut -c 2-3`
# Send data
#curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD3_TEMP_IDX&nvalue=0&svalue=$HDtemp3"

# Temperature HD4
#HDtemp4=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.24681.1.2.11.1.3.4 | cut -c 2-3`
# Send data
#curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD4_TEMP_IDX&nvalue=0&svalue=$HDtemp4"


# Remaining HD size
#size=`snmpget -v 2c -c $PASSWORD -O qv $LKIP 1.3.6.1.4.1.24681.1.2.17.1.5.1 | cut -c 2-7`
# Send data
#curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HD_REMAIN_IDX&nvalue=0&svalue=$size"
fi

else
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$LK_IDX" | grep "Status" | grep "Off" > /dev/null
# NAS uitgeschakeld
if [ $? -eq 0 ] ; then
echo "LK already OFF"
exit
else
echo "LK OFF"
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$LK_IDX&switchcmd=Off"
fi

fi
---CUT-------

oczywiście chmod +x lk.sh
i do crona co pięć minut.
To jest skrypt z forum dostosowany dla mnie(nie jestem autorem). W ten sam sposób odczytuje temp i stan systemu z QNAPA i niedługo zrobie zczytywaniez UPsa (EATON)
pzdr ŁS
<t></t>
Odpowiedz


Wiadomości w tym wątku

Skocz do:


Użytkownicy przeglądający ten wątek: 1 gości