Ik heb het script iets aangepast. Nu werkt het op mijn DS216+II met DSM 6.2
Het script met uitbreiding om de status van de HDDs uit telezen en te rapporteren:
Let op: Creëer 2
extra virtuele sensors type Tekst, en verander de IDX variabelen zorgvuldig,
nadat je de virtuele sensoren hebt toegevoegd !!!!
HDD Status (1=Normal, 2=Initialized,3=NotInitialized,4=SystempartitionFailed,5=crashed)
Maak voor de zekerheid een backup van de database
#!/bin/bash
# Settings
NASIP="<IP adres SYNOLOGY server" # NAS IP Address WOLFSNAS02
COMMUNITY="<Community String>" # SNMP Password/Community
DOMO_IP="<IP adres DOMOTICZ server" # Domoticz IP Address (rasp2b001)
DOMO_PORT="<Domoticz poortnummer" # Domoticz Port
NAS_IDX="310" # NAS Switch IDX
NAS_HD1_TEMP_IDX="319" # NAS HD1 Temp IDX
NAS_HD2_TEMP_IDX="320" # NAS HD2 Temp IDX
NAS_HD_SPACE_IDX="318" # NAS HD Space IDX in Go
NAS_HD_SPACE_PERC_IDX="317" # NAS HD Space IDX in %
NAS_CPU_IDX="315" # NAS CPU IDX
NAS_MEM_IDX="316" # NAS MEM IDX
NAS_HD1_STATUS_IDX="326" # NAS HD1 Status
NAS_HD2_STATUS_IDX="327" # NAS HD2 Status
# Check if NAS in online
PINGTIME=`ping -c 1 -q $NASIP | awk -F"/" '{print $5}' | xargs`
echo $PINGTIME
if expr "$PINGTIME" '>' 0
then
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "On" > /dev/null
if [ $? -eq 0 ] ; then
echo "NAS already ON"
else
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"
fi
# Temperature HD1
HDtemp1=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.6.0`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_HD1_TEMP_IDX&nvalue=0&svalue=$HDtemp1"
# Temperature HD2
HDtemp2=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.6.1`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_HD2_TEMP_IDX&nvalue=0&svalue=$HDtemp2"
# Status HD1
HDStatus1=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.5.0`
case $HDStatus1 in
1) HDStatus1_txt="The_disk_is_funcioning_normally"
;;
2) HDStatus1_txt="The_disk_has_system_partitions_but_no_data"
;;
3) HDStatus1_txt="Disk_is_not_partitioned"
;;
4) HDStatus1_txt="Partitions_on_the_disk_are_damaged"
;;
5) HDStatus1_txt="The_disk_is_damaged"
;;
*) HDStatus1_txt="Unknown_status"
;;
esac
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_HD1_STATUS_IDX&nvalue=0&svalue=$HDStatus1_txt"
# Status HD2
HDStatus2=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.6574.2.1.1.5.1`
# Send data
case $HDStatus2 in
1) HDStatus2_txt="The_disk_is_funcioning_normally"
;;
2) HDStatus2_txt="The_disk_has_system_partitions_but_no_data"
;;
3) HDStatus2_txt="Disk_is_not_partitioned"
;;
4) HDStatus2_txt="Partitions_on_the_disk_are_damaged"
;;
5) HDStatus2_txt="The_disk_is_damaged"
;;
*) HDStatus2_txt="Unknown_status"
;;
esac
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_HD2_STATUS_IDX&nvalue=0&svalue=$HDStatus2_txt"
# Free space volume in Go
HDUnit=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.2.1.25.2.3.1.4.51` # Change OID to .38 on DSM 5.1 or .41 on DSM 6.0+, .51 on DSM 6.2
HDTotal=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.2.1.25.2.3.1.5.51` # Change OID to .38 on DSM 5.1 or .41 on DSM 6.0+, .51 on DSM 6.2
HDUsed=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.2.1.25.2.3.1.6.51` # Change OID to .38 on DSM 5.1 or .41 on DSM 6.0+, .51 on DSM 6.2
HDFree=$((($HDTotal - $HDUsed) * $HDUnit / 1024 / 1024 / 1024))
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_HD_SPACE_IDX&nvalue=0&svalue=$HDFree"
# Free space volume in percent
HDTotal=`snmpget -c $COMMUNITY -v2c -O qv $NASIP .1.3.6.1.2.1.25.2.3.1.5.51` # Change OID to .38 on DSM 5.1 or .41 on DSM 6.0+, .51 on DSM 6.2
HDUsed=`snmpget -c $COMMUNITY -v2c -O qv $NASIP .1.3.6.1.2.1.25.2.3.1.6.51` # Change OID to .38 on DSM 5.1 or .41 on DSM 6.0+, .51 on DSM 6.2
HDFreePerc=$((($HDUsed * 100) / $HDTotal))
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_HD_SPACE_PERC_IDX&nvalue=0&svalue=$HDFreePerc"
# CPU utilisation
CpuUser=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.11.9.0`
CpuSystem=`snmpget -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.11.10.0`
CpuUse=$(($CpuUser + $CpuSystem))
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_CPU_IDX&nvalue=0&svalue=$CpuUse"
# Free Memory Used in %
tmpMemAvailable=`snmpwalk -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.4.6.0`
MemAvailable=${tmpMemAvailable%% *}
tmpMemtotal=`snmpwalk -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.4.5.0`
Memtotal=${tmpMemtotal%% *}
tmpMemShared=`snmpwalk -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.4.13.0`
MemShared=${tmpMemShared%% *}
tmpMemBuffer=`snmpwalk -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.4.14.0`
MemBuffer=${tmpMemBuffer%% *}
tmpMemCached=`snmpwalk -v 2c -c $COMMUNITY -O qv $NASIP 1.3.6.1.4.1.2021.4.15.0`
MemCached=${tmpMemCached%% *}
MemFREE=$(($MemAvailable + $MemShared + $MemBuffer + $MemCached))
MemUsepercent=$(((($Memtotal - $MemFREE) * 100) / $Memtotal))
#// For Available use MemUsepercent=$(((($MemFREE) * 100) / $Memtotal))
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NAS_MEM_IDX&nvalue=0&svalue=$MemUsepercent"
else
# Ping deed het niet
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "Off" > /dev/null
if [ $? -eq 0 ] ; then
echo "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